接收执行从主活动内的片段传出呼叫期间未恢复的活动的停止

时间:2017-01-09 05:56:45

标签: java android phone-state-listener

用户切断拨出电话后,我的活动未恢复,在拨打电话时显示如下错误。

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)

我还在下面添加了电话号码

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);

我不知道这个问题是什么。我想在断电后恢复我的申请。 我的电话呼叫状态监听器位于

之下
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 个答案:

答案 0 :(得分:0)

启动手机动作意图后尝试使用onPause()方法。

然后使用onResume()方法。

答案 1 :(得分:0)

试试这个;

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

这不需要任何检查,通过电话再次显示应用程序。