【发布时间】:2017-08-12 19:21:56
【问题描述】:
我有一个带有打开第二个屏幕的按钮的前屏幕。第二个屏幕可能需要几秒钟才能加载,所以我想在加载时显示一个对话框。我的问题是加载第二个屏幕时对话框不显示,但是当我从第二页返回到第一页时它显示。如果我注释掉 startActivity 以打开第二页,则对话框显示正常。我对 android 编程相当陌生 - 我想这与线程有关。
//code snippet from inside onCreate:
NewGame.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
//does not get displayed before 2nd page opens
showDialog(DIALOG2_KEY);
//shows fine if next 2 lines commented out
Intent i = new Intent(screen1.this, SudukuXL.class);
startActivity(i);
我已经使用onPause() 处理了返回前屏幕时显示的对话框。我尝试使用线程将对话框与startActivity 分开,但我没有运气。任何帮助将不胜感激。
我使用 Android 示例中的代码来创建对话框。我包括以下供参考:
protected Dialog onCreateDialog(int id) {
switch (id) {
case DIALOG2_KEY: {
ProgressDialog dialog = new ProgressDialog(this);
dialog.setMessage("Loading...");
dialog.setIndeterminate(true);
dialog.setCancelable(true);
return dialog;
}
}
return null;
}
【问题讨论】: