FragmentDialog::Can not perform this action after onSaveInstanceState

来源:互联网 发布:淘宝账号怎么修改密码 编辑:程序博客网 时间:2024/06/17 22:51

 在一个程序中使用fragment+异步更新界面,今天出现发现异常,记录解决办法。

 异常:java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState;

 分析:仔细查看后发现,是由于异步线程结束后,要弹出对话框提示,但是这时候fragment已经进入后台,所以抛出这个异常;

 解决办法:在线程运行结束后,需要弹出对话框的时候,先做一个判断isResumed()。google给的文档中是这样说的:

public final boolean isResumed ()

Return true if the fragment is in the resumed state. This is true for the duration of onResume() and onPause() as well.

翻译:当fragment在resumed状态时返回true,即fragment在生命周期的onResume()和onPause()之间时返回true。




1 0
原创粉丝点击