是否可以在加载过程中对活动执行加载屏幕/对话框?
我所有的页面都是单类。这感觉有点不正常。
我尝试使用加载对话框。这是我的活动的创建。
ProgressDialog dialog = ProgressDialog.show(MyActivity.this, "",
"Loading. Please wait...", true);
onFill(name);
dialog.cancel();
这在:(不起作用
例如,我的意图:
Intent intent = new Intent();
intent.setClass(main_list.this, settings.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivity(intent);
System.exit(0);
在MyActivity
onCreate
试试这个
dialog = ProgressDialog.show(MyActivity.this, "",
"Loading. Please wait...", true);
new Thread(new Runnable() {
@Override
public void run()
{
//do here your work i.e. call onFill(name);
runOnUiThread(new Runnable() {
@Override
public void run()
{
dialog.dismiss();
}
});
}
}).start();
显示后,您在ProgressDialog
上调用cancel()
ProgressDialog dialog = ProgressDialog.show(MyActivity.this, "",
"Loading. Please wait...", true);
onFill(name);
dialog.cancel();
我不知道onFill(name)
做什么,但也许您想将取消调用放在该方法中,这意味着您希望将ProgressDialog
设置为成员变量,或者只是将调用 show()
也放在该方法中。