2

I want to make a phone call and after the call ends I want to come back the Activity which started a call.

Code to start a call :

// Start a call
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:" + phoneNumber));
startActivity(callIntent);

Code to handle coming back to activity :

// Monitor phone call activities
private class PhoneCallListener extends PhoneStateListener {

    private boolean isPhoneCalling = false;

    String TAG = "PhoneCallListener";

    @Override
    public void onCallStateChanged(int state, String incomingNumber) {

        // If call ringing
        if (state == TelephonyManager.CALL_STATE_RINGING) {

            Log.d(TAG, "Call ringing, number : " + incomingNumber);
        }
        // Else if call active
        else if (state == TelephonyManager.CALL_STATE_OFFHOOK) {

            Log.d(TAG, "Call active");

            isPhoneCalling = true;
        }
        // Else if call idle
        else if (state == TelephonyManager.CALL_STATE_IDLE) {

            Log.d(TAG, "Call idle");

            if (isPhoneCalling) {

                isPhoneCalling = false;

                // Finish native call application to come back to this
                // activity
                Intent i = new Intent(getIntent());
                i.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
                startActivity(i);
            }

        }
    }
} 

Using finish() does not work. It stays on call application.

How do I come back to the Activity that started a phone call?

Geek
  • 8,280
  • 17
  • 73
  • 137

0 Answers0