执行暂停的活动,该活动在重新创建方法后未恢复 [英] performing pause of activity that is not resumed after recreate method

查看:147
本文介绍了执行暂停的活动,该活动在重新创建方法后未恢复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个HoneyComb项目,在我的主Activity中的onResum()方法中使用recreate()方法后出现错误.

I have a project for HoneyComb and I get an error after use recreate() method at onResum() method in my main Activity.

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)

我创建了一个新项目,向您展示发生了什么事.

I create a new project to show you what's happen.

您可以在 http://xp-dev.com/svn/RecreateError/中找到它行李箱/

我不知道我怎么了,但是我启动了Activity并记录了Activity的生命周期. 结果:

I don't know what's my fault but I start Activity and log the Activity's lifecycle. The result:

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

现在,我按下操作栏图标激活重新创建标志并更改为其他应用程序...

Now I press the Action Bar Icon to activate the recreate flag and change to other app...

11-10 22:30:26.390: I/seasons log(2274): onPause()
11-10 22:30:27.080: I/seasons log(2274): onStop()

然后在激活了recreate标志的情况下返回到我的活动,将在onResume()处执行recreate().

And return to my Activity with recreate flag activated what will done recreate() at 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()

暂停吗?但是我的活动可见,我做错了什么?正确的状态不是onResume()吗?

onPause? But my Activity is visible, what I'm doing wrong? The correct status aren't onResume()?

现在,如果我切换到另一个应用程序,则会收到错误消息.

And now if I change to another app I get the error.

感谢您的时间,并为我的英语不好对不起.

Thanks for your time and sorry for my bad English.

目前我不了解文件管理器HD之类的应用程序如何执行此操作.

At this time I don't understand how applications like File Manager HD do this action.

两个活动:主要活动A,以BreferenceFragment为主要内容的活动B.

Two Activities: Main Activity A, Activity B with PreferenceFragment as main content.

一个可以在Holo和Holo.Light之间更改主题的选项, 活动B用PreferenceFragment中的OnSharedPreferenceChangeListener方法更改,但是当我们回到onResume()处的主活动recreate()方法失败时,该怎么办?

One option that changes theme between Holo and Holo.Light, Activity B changes with a OnSharedPreferenceChangeListener method in PreferenceFragment but when we come back to the Main Activity recreate() method at onResume() fails, how to do This?

我很困惑.抱歉.

推荐答案

为此,请使用处理程序:

To do this, use a handler:

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

这不会再崩溃了.

这篇关于执行暂停的活动,该活动在重新创建方法后未恢复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆