我知道当我尝试在后台线程上显示ProgressDialog时会抛出异常Can't create handler inside thread that has not called Looper.prepare(),
因为我们正在尝试从后台线程修改UI.但是当我们在后台线程中忽略该对话框时,不会抛出任何异常.为什么我们在后台线程中关闭对话框时没有抛出异常,因为我们也是后台线程中的modifyng UI.
谢谢
这是Dialog的dismiss()方法的代码,显示了为什么没有抛出异常并且dismiss有效:
/**
* Dismiss this dialog, removing it from the screen. This method can be
* invoked safely from any thread. Note that you should not override this
* method to do cleanup when the dialog is dismissed, instead implement
* that in {@link #onStop}.
*/
public void dismiss() {
if (Thread.currentThread() != mUiThread) {
mHandler.post(mDismissAction);
} else {
mDismissAction.run();
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
278 次 |
| 最近记录: |