我有一个HoneyComb的项目,并在我的主要Activity中使用onResum()方法后使用recreate()方法时收到错误.
11-10 22:05:42.090: E/ActivityThread(1917): Performing pause of activity that is not resumed: {com.blogspot.honeyapp/com.blogspot.honeyapp.Main} 11-10 22:05:42.090: E/ActivityThread(1917): java.lang.RuntimeException: Performing pause of activity that is not resumed: {com.blogspot.honeyapp/com.blogspot.honeyapp.Main} 11-10 22:05:42.090: E/ActivityThread(1917): at android.app.ActivityThread.performPauseActivity(ActivityThread.java:2517) 11-10 22:05:42.090: E/ActivityThread(1917): at android.app.ActivityThread.performPauseActivity(ActivityThread.java:2505) 11-10 22:05:42.090: E/ActivityThread(1917): at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:2483) 11-10 22:05:42.090: E/ActivityThread(1917): at android.app.ActivityThread.access$700(ActivityThread.java:122) 11-10 22:05:42.090: E/ActivityThread(1917): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1031) 11-10 22:05:42.090: E/ActivityThread(1917): at android.os.Handler.dispatchMessage(Handler.java:99) 11-10 22:05:42.090: E/ActivityThread(1917): at android.os.Looper.loop(Looper.java:132) 11-10 22:05:42.090: E/ActivityThread(1917): at android.app.ActivityThread.main(ActivityThread.java:4123) 11-10 22:05:42.090: E/ActivityThread(1917): at java.lang.reflect.Method.invokeNative(Native Method) 11-10 22:05:42.090: E/ActivityThread(1917): at java.lang.reflect.Method.invoke(Method.java:491) 11-10 22:05:42.090: E/ActivityThread(1917): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841) 11-10 22:05:42.090: E/ActivityThread(1917): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599) 11-10 22:05:42.090: E/ActivityThread(1917): at dalvik.system.NativeStart.main(Native Method)
我创建一个新项目,向您展示发生了什么.
你可以在http://xp-dev.com/svn/RecreateError/trunk/找到它
我不知道我的错误是什么,但是我启动了Activity并记录了Activity的生命周期.
结果:
11-10 22:26:45.960: I/seasons log(2274): onCreate() 11-10 22:26:45.990: I/seasons log(2274): onStart() 11-10 22:26:45.990: I/seasons log(2274): onResume()
现在我按动作栏图标激活重新创建标志并更改为其他应用程序…
11-10 22:30:26.390: I/seasons log(2274): onPause() 11-10 22:30:27.080: I/seasons log(2274): onStop()
并返回到我的活动与重新创建标志激活什么将重建()onResume().
11-10 22:33:05.500: I/seasons log(2274): onCreate() 11-10 22:33:05.510: I/seasons log(2274): onStart() 11-10 22:33:05.510: I/seasons log(2274): onResume() 11-10 22:33:05.510: I/seasons log(2274): onPause()
在onPause?但我的活动是可见的,我做错了什么?正确的状态不是onResume()?
现在如果我改变到另一个应用程序,我得到错误.
感谢您的时间,感谢我的英文不好.
在这个时候我不明白应用程序如File Manager HD这样做.
两个活动:主要活动A,活动B以优先权为主要内容.
在Holo和Holo.Light之间改变主题的一个选项,
活动B使用PreferenceFragment中的OnSharedPreferenceChangeListener方法更改,但是当我们回到onResume()上的Main Activity rebuate()方法失败时,该怎么做?
我很讨厌抱歉.
解决方法
为此,请使用处理程序:
Handler handler = new Handler() { @Override public void handleMessage(Message msg) { if(msg.what==MSG_RECREATE) recreate(); } }; @Override protected void onResume() { if(condition) { Message msg = handler.obtainMessage(); msg.what = MSG_RECREATE; handler.sendMessage(msg); } }
这不会崩溃了.