我有一個名爲MyProgressDialog的活動,它包含一個ProgressDialog。這ScreenProgressDialog活動是由意圖稱爲主要活動:調用finish()後,爲什麼不停止android活動?
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();返回;並且啓動顯示一個新的ProgressDialog的Onreate方法。 onDestroy被調用,但ProgressDialog不會隱藏屏幕。在finish()方法之後,活動被關閉。哪裏有問題?謝謝!
但調用完成()後不應該被稱爲Activitiy在我看來onCreate方法。 – Alex 2012-07-14 12:55:17
如果你開始一個新的活動,那麼在方法結束後,將會調用新活動的onCreate。 – Blackbelt 2012-07-14 12:58:04
在破壞自己之前,在finish()方法之後調用onCreate。爲什麼不是onDestroy? – Alex 2012-07-14 13:00:09