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
Inside PhoneStateListener after seeing the call is finished better use:
Intent intent = new Intent(CallDispatcherActivity.this, CallDispatcherActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
Where CallDispatcherActivity is the activity where the user has launched a call (to a taxi service dispatcher, in my case). This just removes Android telephony app from the top, the user gets back instead of ugly code I saw here.
If you are going to use a listener you will need to add this permission to the manifest as well.
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
To return to your Activity
, you will need to listen to TelephonyStates
. On that listener
you can send an Intent
to re-open your Activity
once the phone is idle.
At least thats how I will do it.
// in setonclicklistener put this code:
EditText et_number=(EditText)findViewById(R.id.id_of_edittext);
String my_number = et_number.getText().toString().trim();
Intent callIntent = new Intent(Intent.ACTION_CALL, Uri.parse(my_number));
startActivity(callIntent);
// give permission for call in manifest:
<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:"+number));
startActivity(callIntent);
**Add permission :**
<uses-permission android:name="android.permission.CALL_PHONE" />
This is solution from my point of view:
ok.setOnClickListener(this);
@Override
public void onClick(View view) {
if(view == ok){
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:" + num));
activity.startActivity(intent);
}
Of course in Activity (class) definition you have to implement View.OnClickListener .