Android DialogFragment偶发不能清除的问题
来源:互联网 发布:今日目标软件功能 编辑:程序博客网 时间:2024/04/29 17:03
对话框现在多用DialogFragment来代替Dialog,在关闭对话框时需要dismiss操作;但如下代码偶发不能dismiss的问题:使用在progress dialog中,发送请求是show,请求完成后dismiss。
public static void show(FragmentManager manager) {DiyDialog dialogFragment = new DiyDialog();try {if (!dialogFragment.isAdded()) {FragmentTransaction fragmentTransaction=manager.beginTransaction();fragmentTransaction.add(dialogFragment, TAG);fragmentTransaction.commitAllowingStateLoss();//manager.executePendingTransactions();}} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();}}@SuppressLint("NewApi")public static void closeDialog(FragmentManager manager) {DiyDialog dialogFragment = (DiyDialog) manager.findFragmentByTag(TAG);if (dialogFragment != null) {dialogFragment.dismissAllowingStateLoss();}}
/** * Schedules a commit of this transaction. The commit does * not happen immediately; it will be scheduled as work on the main thread * to be done the next time that thread is ready. * * <p class="note">A transaction can only be committed with this method * prior to its containing activity saving its state. If the commit is * attempted after that point, an exception will be thrown. This is * because the state after the commit can be lost if the activity needs to * be restored from its state. See {@link #commitAllowingStateLoss()} for * situations where it may be okay to lose the commit.</p> * * @return Returns the identifier of this transaction's back stack entry, * if {@link #addToBackStack(String)} had been called. Otherwise, returns * a negative number. */ public abstract int commit(); /** * Like {@link #commit} but allows the commit to be executed after an * activity's state is saved. This is dangerous because the commit can * be lost if the activity needs to later be restored from its state, so * this should only be used for cases where it is okay for the UI state * to change unexpectedly on the user. */ public abstract int commitAllowingStateLoss();
大概的意思是:安排了一个commit操作,但不会立刻执行。而如下的这个还是也进一步说明了:commit操作被安排在主线程异步执行。如果想要立即执行,执行如下函数将会有效。
/** * After a {@link FragmentTransaction} is committed with * {@link FragmentTransaction#commit FragmentTransaction.commit()}, it * is scheduled to be executed asynchronously on the process's main thread. * If you want to immediately executing any such pending operations, you * can call this function (only from the main thread) to do so. Note that * all callbacks and other related behavior will be done from within this * call, so be careful about where this is called from. * * @return Returns true if there were any pending transactions to be * executed. */ public abstract boolean executePendingTransactions();
0 0
- Android DialogFragment偶发不能清除的问题
- 偶发现的request.QueryString问题
- udp connect偶发失败的问题定位
- DialogFragment不能findViewById的解决方法
- Android:DialogFragment的使用
- Android-----DialogFragment的使用
- Android 自定义 DialogFragment 宽度问题
- Android 自定义 DialogFragment 宽度问题
- Android 自定义 DialogFragment 宽度问题
- Android 自定义 DialogFragment 宽度问题
- android的DialogFragment设置全屏之后,里面的View不能充满整个屏幕
- Android中DialogFragment的使用
- easy-ui的datetimebox回显不能清除的问题
- Android DialogFragment
- android Dialogfragment
- android DialogFragment
- Android DialogFragment
- hadoop 运行期间偶发的各种问题积累(简单问题不展示)
- ActiveX控件实现安全的初始化和脚本
- javaweb总结(5) - servlet开发
- Url 传json 数据
- 关于5.0以下Android状态栏背景色变换
- (java)求个数最多的前K个数
- Android DialogFragment偶发不能清除的问题
- 百度地图改变定位图标
- 6个输入框背后的47个设计点
- PAT (Basic Level) Practise (中文)1047. 编程团体赛(20)
- appium测试之滑动操作
- RadioGroup动态添加RadioButton,并且获得事件
- HDU 4500 小Q系列故事——屌丝的逆袭(水题)
- html5本地存储webstorage
- Android简洁架构设计 The Clean Architecture