Unable to pause activity exception in android

吃可爱长大的小学妹 提交于 2019-12-11 23:12:16

问题


Hi I am developing small android application. So my application contains following things. 3 Activities consider A1, A2, A3. A1 is my launcher activity. my application also contains one background service. So when I click on button inside A1 it will start background service.

Inside background service I am starting A2. I am also doing some calculations in service so after those calculations i am starting activity A3 from service only. SO my problem is here when I start service from A1 it will open A2 from service. If I click back from there(A2 to A1) it will come back to A1. But in case of (A1 -> service -> A2 -> A3(this also started from service)) if i click on back it will causes unable to pause activity exception error. It will not resume A1.

When I start activity from service I am using Intent.FLAG_ACTIVITY_NEW_TASK. Where is the problem? need Help Thank you

See this is my error log:

01-17 14:45:03.689: E/AndroidRuntime(27805): FATAL EXCEPTION: main
01-17 14:45:03.689: E/AndroidRuntime(27805): java.lang.RuntimeException: Unable to pause activity { ABC/ ABC.map.MapActivity}: java.lang.IllegalStateException
01-17 14:45:03.689: E/AndroidRuntime(27805):    at android.app.ActivityThread.performPauseActivity(ActivityThread.java:2709)
01-17 14:45:03.689: E/AndroidRuntime(27805):    at android.app.ActivityThread.performPauseActivity(ActivityThread.java:2665)
01-17 14:45:03.689: E/AndroidRuntime(27805):    at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:2643)
01-17 14:45:03.689: E/AndroidRuntime(27805):    at android.app.ActivityThread.access$800(ActivityThread.java:124)
01-17 14:45:03.689: E/AndroidRuntime(27805):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1159)
01-17 14:45:03.689: E/AndroidRuntime(27805):    at android.os.Handler.dispatchMessage(Handler.java:99)
01-17 14:45:03.689: E/AndroidRuntime(27805):    at android.os.Looper.loop(Looper.java:137)
01-17 14:45:03.689: E/AndroidRuntime(27805):    at android.app.ActivityThread.main(ActivityThread.java:4436)
01-17 14:45:03.689: E/AndroidRuntime(27805):    at java.lang.reflect.Method.invokeNative(Native Method)
01-17 14:45:03.689: E/AndroidRuntime(27805):    at java.lang.reflect.Method.invoke(Method.java:511)
01-17 14:45:03.689: E/AndroidRuntime(27805):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
01-17 14:45:03.689: E/AndroidRuntime(27805):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
01-17 14:45:03.689: E/AndroidRuntime(27805):    at dalvik.system.NativeStart.main(Native Method)
01-17 14:45:03.689: E/AndroidRuntime(27805): Caused by: java.lang.IllegalStateException
01-17 14:45:03.689: E/AndroidRuntime(27805):    at android.media.MediaPlayer._stop(Native Method)
01-17 14:45:03.689: E/AndroidRuntime(27805):    at android.media.MediaPlayer.stop(MediaPlayer.java:977)
01-17 14:45:03.689: E/AndroidRuntime(27805):    at  ABC.map.MapActivity.onPause(MapActivity.java:170)
01-17 14:45:03.689: E/AndroidRuntime(27805):    at android.app.Activity.performPause(Activity.java:4564)
01-17 14:45:03.689: E/AndroidRuntime(27805):    at android.app.Instrumentation.callActivityOnPause(Instrumentation.java:1195)
01-17 14:45:03.689: E/AndroidRuntime(27805):    at android.app.ActivityThread.performPauseActivity(ActivityThread.java:2696)
01-17 14:45:03.689: E/AndroidRuntime(27805):    ... 12 more

回答1:


It happens because your A2 Activity is not started. You need to check that onCreate() and onStart() method are finished in your A2 Activity and only after that you have to start A3 Activity.



来源:https://stackoverflow.com/questions/21181562/unable-to-pause-activity-exception-in-android

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