I am launching an activity to make a phone call, but when I pressed the \'end call\' button, it does not go back to my activity. Can you please tell me how can I launch a c
@Dmitri Novikov, FLAG_ACTIVITY_CLEAR_TOP
clears any active instance on top of the new one. So, it may end the old instance before it completes the process.
When PhoneStateListener
is used, one need to make sure PHONE_STATE_IDLE
following a PHONE_STATE_OFFHOOK
is used to trigger the action to be done after the call. If the trigger happens upon seeing PHONE_STATE_IDLE
, you will end up doing it before the call. Because you will see the state change PHONE_STATE_IDLE -> PHONE_STATE_OFFHOOK -> PHONE_STATE_IDLE.
you can use startActivityForResult()
Try using:
finish();
at the end of activity. It will redirect you to your previous activity.
Add this is your xml: android:autoLink="phone"
This is regarding the question asked by Starter.
The problem with your code is that you are not passing the number properly.
The code should be:
private OnClickListener next = new OnClickListener() {
public void onClick(View v) {
EditText num=(EditText)findViewById(R.id.EditText01);
String number = "tel:" + num.getText().toString().trim();
Intent callIntent = new Intent(Intent.ACTION_CALL, Uri.parse(number));
startActivity(callIntent);
}
};
Do not forget to add the permission in manifest file.
<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>
or
<uses-permission android:name="android.permission.CALL_PRIVILEGED"></uses-permission>
for emergency number in case DIAL
is used.