我有一个名为 MyProgressDialog 的活动,其中包含一个 ProgressDialog。此 ScreenProgressDialog 活动由 Intent 在 Main 活动中调用:
if(msg.what == SET_PROGRESS){
intent.putExtra("action", "set");
...
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
else if(msg.what == SHOW_PROGRESS){
intent.putExtra("action", "show");
...
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
else if(msg.what == HIDE_PROGRESS){
intent.putExtra("action", "hide");
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(intent);
}
这是 MyProgressDialog 活动:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.e("screenPD", "spd created");
extras = getIntent().getExtras();
pd = new ProgressDialog(this);
...setting the pd...
pd.show();
Log.e("screenPD", "spd shown");
}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
setIntent(intent);
int newTitle = intent.getExtras().getInt("title");
if (intent.getExtras().getString("action").equals("set")){
pd.set methods...
pd.show();
Log.e("DialogSET", "DialogSET "+intent.getExtras().getInt("progress"));
}
else if (intent.getExtras().getString("action").equals("show")){
pd.set methods...
pd.show();
Log.e("DialogSHOW", "DialogSHOW "+progress);
}
else if (intent.getExtras().getString("action").equals("hide")){
pd.dismiss();
this.finish();
Log.e("DialogHIDE", "DialogHIDE");
return;
}
}
@Override
public void onDestroy() {
super.onDestroy();
Log.e("screenPD", "destroyed");
}
这是 LogCat:
DialogHIDE(2615): DialogHIDE
screenPD(2615): spd created
screenPD(2615): spd shown
screenPD(2615): destroyed
所以第三个意图开始了,调用了finish(); 返回; 并启动 Onreate 方法,该方法显示一个新的 ProgressDialog。onDestroy 被调用,但 ProgressDialog 不会从屏幕上隐藏。在完成()方法之后,活动将被关闭。问题出在哪里?谢谢!