user649467
user649467

Reputation: 41

how to come back to my application after ACTION_CALL in android

I've got one question regarding the intent action ACTION_CALL.

What is the correct way of getting back to the own application/activity after the user ends the call?

Intent intent = new Intent(Intent.ACTION_CALL);
       intent.setData(Uri.parse("tel:" +m1));

startActivity(intent);

I have made the call using the above code. Please provide me with a solution to call my own activity after the call action.

Upvotes: 3

Views: 2263

Answers (3)

mhadidg
mhadidg

Reputation: 1834

I run with the same problem, and ended up solving it like this:

  1. Make a Callback interface with single (or multiple if you want) methods
  2. Implement that interface in your activity
  3. Make a reference to that interface inside PhoneStateListener class
  4. Call a method within that interface when the call ended

public class CallTracker extends PhoneStateListener implements Runnable {
  private Context mActivity;
  private Callback mCallback;

  public interface Callback {
    void onCallEnded();
  }

  public CallTracker(Activity activity) {
    super();
    mActivity = activity;

    if (mActivity instanceof Callback) {
      mCallback = (Callback) mActivity;
    }
  }

  @Override public void onCallStateChanged(int state, String incomingNumber) {
    if (state == TelephonyManager.CALL_STATE_IDLE) {
         mCallback.onCallEnded();
    }
}

public class CallerActivity extends AppCompatActivity implements
    CallTracker.Callback {

    @Override public void onCallEnded() {
    Toast.makeText(this, "Call ended!", Toast.LENGTH_SHORT).show();
    }
}

Upvotes: 0

Uday
Uday

Reputation: 6023

AFter the endofcall.......it just had to come back to the activity..!! you can handle that one onRestart();

Upvotes: 0

P Varga
P Varga

Reputation: 20269

unfortunately some phones have settings to force going into for example the Call Log after a call...

However, you can run a loop after your startActivity to check TelephonyManager.getCallState, and when it's again TelephonyManager.CALL_STATE_IDLE, you can restart your own Activity

be sure to add some sleep to the loop

Upvotes: 3

Related Questions