popBackStack()saveInstanceState后() [英] popBackStack() after saveInstanceState()

查看:169
本文介绍了popBackStack()saveInstanceState后()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个问题,我有多个片段的活动。对于任何个别片段,您可以执行搜索操作,其工作就好了... ...如果你从任何一个片段进行搜索,它会显示一个新的活动来处理搜索,然后将结果返回给活动处理显示新片段。问题是,搜索操作后,我希望能够以清除(几乎)所有的碎片远用 popBackStackImmediate(...),自 saveInstanceState(...)叫,我得到一个说异常:

I'm running into an issue where I have an Activity with multiple fragments. For any individual fragment, you can perform a search operation, which works just fine...if you search from any of the fragments, it will display a new Activity to handle the searching, then return the result to the Activity to handle displaying a new fragment. The problem is, after a search operation, I want to be able to clear (almost) all the fragments away using popBackStackImmediate(...) and since saveInstanceState(...) was called, I get an exception that says:

"java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState"

不知道如何从后面栈中弹出后的onSaveInstanceState 被称为?

推荐答案

显然,我的问题从的onActivityResult(...)

Apparently my issue spawned from the call being made in onActivityResult(...)

我能够通过把里面一个Runnable的UI修改code,然后发布了Runnable主线程来解决这个问题:

I was able to fix the issue by putting the UI modification code inside a Runnable, then posting the Runnable to the main thread:

Runnable r = new Runnable() {
    @Override
    public void run() {
        // UI code here
    }
};
Handler h = new Handler();
h.post(r);

这篇关于popBackStack()saveInstanceState后()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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