Android 4.4.2 - java.lang.RuntimeException:正在停止未恢复的活动 [英] Android 4.4.2 - java.lang.RuntimeException: Performing stop of activity that is not resumed
问题描述
我在 4.4.2 设备上遇到此异常.无法在 Android 4.3 或更低版本的设备上重现.
I'm getting this exception on a 4.4.2 device. Not reproducible on Android 4.3 device or lower.
设置是我有一个家庭活动(支持ActionBarActivity
的子类).家庭活动检查一个布尔标志,如果为真,则启动启动画面活动(是的,理想情况下,启动画面在家庭活动之前出现,但假设我现在无法将其更改为那样工作).
Setup is I have a home activity (subclass of support ActionBarActivity
). The home activity checks a boolean flag, and if true, launches a splash screen activity (yes, ideally the splash comes before the home activity, but let's assume I can't change it to work that way for now).
启动画面使用 startActivityForResult
启动,它从服务器下载一些配置选项,然后完成并将结果返回给 home Activity.
The splash screen is launched with startActivityForResult
, it downloads some config options from the server, then finishes and returns the result back to the home activity.
奇怪的是,这在 4.3 及以下版本上运行良好,但在 4.4 设备上,我收到上述异常(完整堆栈跟踪):
Weird thing is this works fine on 4.3 and below, but on 4.4 devices, I get the above exception (full stack trace):
02-21 13:36:16.733 24409-24409/test.player E/ActivityThread﹕ Performing stop of activity that is not resumed: {test.player/test.ui.actvities.HomeActivity}
java.lang.RuntimeException: Performing stop of activity that is not resumed: {test.player/test.ui.actvities.HomeActivity}
at android.app.ActivityThread.performStopActivityInner(ActivityThread.java:3147)
at android.app.ActivityThread.handleStopActivity(ActivityThread.java:3234)
at android.app.ActivityThread.access$1100(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1223)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
基于上述,看起来 onStop(因为我在 onCreate 上启动了启动活动)在 Home Activity 的 onResume 之前被调用.
Based on the above, it looks like onStop (because I launch the splash activity on onCreate) is called before onResume for the Home Activity.
为什么现在这会导致 4.4.x 出现问题?
Why is this now causing problems in 4.4.x?
推荐答案
这对我来说似乎不对.启动活动现在将是堆栈中的顶部活动,因此 HomeActivity
onStop 生命周期方法最终将被调用.巧合的是,我将启动活动的 startActivity
调用从 onCreate
移动到 HomeActivity
中的 onResume
,并且错误消失了.
That doesn't seem right to me. The splash activity would now be the top activity in the stack, so the HomeActivity
onStop lifecycle method would get called eventually. Coincidentally, I moved the startActivity
call for the splash activity from onCreate
to onResume
in the HomeActivity
, and the error goes away.
这篇关于Android 4.4.2 - java.lang.RuntimeException:正在停止未恢复的活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!