When I run following code I see that "unfortunately dialer has stopped working".
Here is a snippet of my code:
DialerActivity.java
package com.test;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.net.Uri;
import android.widget.Button;
import android.view.*;
public class DialerActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button callButton=(Button) findViewById(R.id.callButton);
callButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v)
{
try {
Intent CallIntent =
new Intent(Intent.ACTION_CALL,Uri.parse("tel:9563460376"));
CallIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(CallIntent);
}
catch(Exception e)
{
}
}
});
}
}
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<button android:id="#+id/callButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="ShowDialer"
android:background="#d3d3d3">
</button>
</LinearLayout>
string.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hell">sanjoy</string>
<string name="app_name">Test</string>
<string name="button">ShowDialer</string>
</resources>
Why would this be happening?
Intent serviceIntent = new Intent(context, YourClass.class);
serviceIntent.setAction("android.intent.action.NEW_OUTGOING_CALL");
serviceIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(serviceIntent);
try this one, and not forget to add permission in Manifest.
Related
It Shows no error on Android Studio but app even not starting on phone.Is there any problem with the code.I feel like there may be any mistakes in syntax but i am not able to find one.Please help me.
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
private Button bDriver,bCustomer;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button bDriver=(Button)findViewById(R.id.driver);
Button bCustomer=(Button)findViewById(R.id.customer);
bDriver.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent=new
Intent(MainActivity.this,DriverLoginActivity.class);
startActivity(intent);
finish();
}
});
bCustomer.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent ryt=new
Intent(MainActivity.this,CustomerLoginActivity.class);
startActivity(ryt);
finish();
}
});
}
}
And activity_main.xml is this and please explain if there is any problem related to SDK version also upload the detail.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.trillcore.uber.MainActivity">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/driver"
android:layout_below="#+id/customer"
android:text="I am a Driver"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="I am a Customer"
android:layout_above="#+id/driver"
android:id="#+id/customer"/>
</RelativeLayout>
Please help me figure out why my string isn't passing between my activities in android studio. I ran this script on my phone but the string I'm passing from my main activity is passing to my secondary activity. I'm going through an android teach yourself book and I believe the issue is in my XML.
Here's my XML code:
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.example.owner.hour3application.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!" />
</RelativeLayout>
activity_secondary.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.example.owner.hour2application.SecondaryActivity">
<TextView
android:id="#+id/message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:textAppearance="?android:attr/textAppearanceLarge" />
</android.support.design.widget.CoordinatorLayout>
Main Activity
package com.example.owner.hour2application;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button activityButton = (Button) findViewById(R.id.Button);
if (activityButton != null) {
activityButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent startIntent = new Intent(MainActivity.this, SecondaryActivity.class);
startIntent.putExtra("com.example.owner.MESSAGE", "Hello SecondaryActivity");
startActivity(startIntent);
}
});
}
}
}
Secondary Activity
package com.example.owner.hour2application;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;
public class SecondaryActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_secondary);
Intent intent = getIntent();
String message = intent.getStringExtra("com.example.owner.MESSAGE");
TextView messageTextView = (TextView) findViewById(R.id.message);
if (messageTextView != null) {
messageTextView.setText(message);
}
}
}
Thanks guys sorry I posted the wrong main activity. The issue was in string.xml the string name was wrong. Thanks!
I Change an activity background color in eclipse,but I don't any change in run time. why?
this is activity XML code,I use android:background="#ff0000" to change background cokor:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:content=".TestingDetailsActivity"
android:background="#ff0000">
<Button
android:id="#+id/btnExistsTest"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/ExamList" />
</LinearLayout>
and java code:
package com.tutecentral.restfulapiclient;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class TestingDetailsActivity extends Activity {
Button btnExistsTest;
protected void onCreate() {
//super.onCreate(savedInstanceState);
setContentView(R.layout.activity_testing);
btnExistsTest=(Button) findViewById(R.id.btnExistsTest);
btnExistsTest.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent i=new Intent(TestingDetailsActivity.this,ExamListActivity.class);
startActivity(i);
}
}) ;
}
}
Manually uninstall the APK file from your phone and then re-run the app from your IDE. Sometimes these kind of glitches happen.
My code is written to first bring up a button in the LoginActivity and then when pressed load another activity. But as of right now, the app crashes both on my S4 and an emulator on launch. I have tried debugging mode but haven't received any useful information. Here is my LoginActivity code (main activity):
package com.JTInc.tag;
import android.app.FragmentTransaction;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
public class LoginActivity extends FragmentActivity {
public void gotomap (View View){
Intent ii = new Intent(getActivity(), MapActivity.class);
startActivity(ii);
}
private void startActivity(Intent ii) {
// TODO Auto-generated method stub
}
private Context getActivity() {
//TODO Auto-generated method stub
return null;
}
}
Here is the mapviewer.xml code (the main layout)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button
android:id="#+id/gotomap"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/gotomap"
android:onClick="gotomap" />
</LinearLayout>
Any and all help is appreciated, Thanks.
I start a new activity when clicking on a button , but the content(ui components) of the new activity doesn't appear , why ??
button listener to start new activity
m_sendButton.setOnClickListener(
new OnClickListener(){
public void onClick(View view) {
Intent in = new Intent(context, SendMessageForm.class);
// i.putExtra("id","4");
context.startActivity(in);
//Toast toast = Toast.makeText(context, "Error. Please try again later", Toast.LENGTH_SHORT);
//toast.show();
} }
);
SendMessageForm.java
import android.app.Activity;
import android.os.Bundle;
public class SendMessageForm extends Activity {
public void onCreat(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.search_result_form);
}
}
search_result_form.xml (just for test)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/rootLayout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button android:text="Send" android:id="#+id/btnBacksds"
android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
</LinearLayout>
You have a typo in your onCreate method. The method name says onCreat - it's missing an 'e':
import android.app.Activity;
import android.os.Bundle;
public class SendMessageForm extends Activity {
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.search_result_form);
}
}
In general it's useful to use the #Override annotation to help you catch any mistakes such as this. If the parent class does not have a matching method signature then your IDE (at least Eclipse does this) will warn you or present an error.