【发布时间】:2018-05-21 16:18:06
【问题描述】:
在您将此问题视为重复问题之前,只需知道我看到了这些:
AlertDialog setmessage not working inside Asynctask
ProgressDialog does not want to update the message
Android: Progress Dialog change ProgressDialog.setMessage() while loading
Changing Progress Dialog Message While Running
但没有运气。
我正在尝试更新 ProgressDialog 中显示的消息。是的。就这么简单。
现在我的代码如下所示:
private BroadcastReceiver createMapReceiver(MapEntry entry) {
return new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
...
dialogMessage = getString(R.string.maps_download_extracting)
.concat("\n\n")
.concat(getString(R.string.maps_download_suffix));
Runnable changeMessage = () -> {
downloadingDialog.setMessage(dialogMessage);
downloadingDialog.show();
};
runOnUiThread(changeMessage);
...
}
};
}
但是消息没有更新。其他一切都按预期工作。我错过了什么?
【问题讨论】:
-
你不需要
runOnUiThread,onReceive已经在 mainThread 上调用过。onReceive是否被调用? -
是的。它是。这就是我所说的“其他一切都按预期工作”的意思:p。我需要 runOnUiThread 因为 onReceive 没有在 UI 线程上运行。
-
它如何不在 UI 线程上运行?在
onReceive之前downloadingDialog的状态是什么?正在显示吗? -
正在显示下载对话框。关键是,无论是否在 UI 线程上运行,它都不会更新消息。两种方法我都试过了。
-
你是对的。 onreceive() 在 UI 线程上运行。谢谢 :) 不过还是不行 :(