Coming back to an Activity after making a phone call

余生颓废 提交于 2020-01-04 13:27:01

问题


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?

来源:https://stackoverflow.com/questions/17654608/coming-back-to-an-activity-after-making-a-phone-call

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!