Receive Performing stop of activity that is not resumed during outgoing call from fragment inside main activity

165 views Asked by At

My Activity is not resume after user cuts outgoing call it shows below error when phone call made.

Performing stop of activity that is not resumed: {.MainActivity}
                                                               java.lang.RuntimeException: Performing stop of activity that is not resumed: {.MainActivity}
                                                                   at android.app.ActivityThread.performStopActivityInner(ActivityThread.java:3601)
                                                                   at android.app.ActivityThread.handleStopActivity(ActivityThread.java:3690)
                                                                   at android.app.ActivityThread.access$1100(ActivityThread.java:178)
                                                                   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1499)
                                                                   at android.os.Handler.dispatchMessage(Handler.java:111)
                                                                   at android.os.Looper.loop(Looper.java:194)
                                                                   at android.app.ActivityThread.main(ActivityThread.java:5637)
                                                                   at java.lang.reflect.Method.invoke(Native Method)
                                                                   at java.lang.reflect.Method.invoke(Method.java:372)
                                                                   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:959)
                                                                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754)

I also added phonecall code at below

PhoneCallListener phoneListener = new PhoneCallListener();
TelephonyManager telephonyManager = (TelephonyManager) ContextGetter.getContext().getSystemService(Context.TELEPHONY_SERVICE);                                                  telephonyManager.listen(phoneListener, PhoneStateListener.LISTEN_CALL_STATE);
String temp = "tel:+91" + "xxxxxxxxxx";                                                                                     Intent callIntent = new Intent(Intent.ACTION_CALL);                                         callIntent.setData(Uri.parse(temp));                                    startActivity(callIntent);

I don't know whats the problem. I want to resume my application after call cut. My Phone call state listener is below

if ( TelephonyManager.CALL_STATE_OFFHOOK == state )
{
    if(incomingNumber.equalsIgnoreCase("+91"+"xxxxxxxxxx"))
    {
            isPhoneCalling = true;
    }
}
if ( TelephonyManager.CALL_STATE_IDLE == state ) {
    if ( isPhoneCalling )
    {
        Activity activity = getActivity();
        if(activity != null && isAdded())
        {
            Intent i = getActivity().getBaseContext().getPackageManager().getLaunchIntentForPackage(getActivity().getBaseContext().getPackageName());
            i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
            startActivity(i);
        }
        isPhoneCalling = false;
    }
}
2

There are 2 answers

0
Sudhanshu Mittal On

Try using onPause() method after you start the phone Action intent.

and then use onResume() method after that.

8
Manoj Perumarath On

Try this;

 Intent intent = new Intent(Intent.ACTION_CALL);
            String uri = "tel:" + number;
            intent.setData(Uri.parse(uri));
            startActivity(intent);

This doesn't require any check, after phone call it shows application again.