问题描述
我遇到了一个问题,我有多个片段的活动。对于任何个别片段,您可以执行搜索操作,其工作就好了... ...如果你从任何一个片段进行搜索,它会显示一个新的活动来处理搜索,然后将结果返回给活动处理显示新片段。问题是,搜索操作后,我希望能够以清除(几乎)所有的碎片远用 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后()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!