有一个由意图触发的活动:设置、显示和隐藏 ProgressDialog。当它设置并显示活动时工作正常,但是当调用隐藏时,而不是调用 onDestroy 方法,而是调用 onCreate。这是活动开始时的 LogCat:
SHOW_PROGESS
SET_PROGESS
onCreate
onStart
onResume
SET_PROGESS
onPause
DialogSET 15
onResume
SET_PROGESS
onPause
DialogSET 16
onResume
...
ProgressDialog 在 onNewIntent(Intent intent) 方法中设置和显示。但是当隐藏任务被调用时
pd.dismiss();
finish();
被调用,而不是调用 onDestroy 调用 onCreate:
HIDE_PROGESS
onPause
DialogHIDE
onResume
onPause
onCreate
onStart
onResume
onStop
destroyed
Activity -activityName- has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@41347af0 that was originally added here android.view.WindowLeaked
没有 ProgessDialog 有白色显示。按下 BACK 按钮后
onPause
onDestroy
被调用,然后我可以看到我想要的。如何解决我不应该按下 BACK 按钮再次调用 onDestroy 的问题?
意图是这样开始的:
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.setAction(intent.ACTION_VIEW);
startActivity(intent);
谢谢!
编辑:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
extras = getIntent().getExtras();
progress = 0;
max = extras.getInt("max");
title = extras.getInt("title");
pd = new ProgressDialog(this);
pd.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
pd.setCancelable(false);
Log.w("screenPD", "onCreate");
}
@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.setTitle(newTitle);
pd.setMessage(intent.getExtras().getString("message"));
max = intent.getExtras().getInt("max");
pd.setMax(max);
pd.setProgress(intent.getExtras().getInt("progress"));
pd.show();
Log.e("DialogSET", "DialogSET "+intent.getExtras().getInt("progress"));
}
else if (intent.getExtras().getString("action").equals("show")){
pd.setProgress(intent.getExtras().getInt("progress"));
pd.setMessage(intent.getExtras().getString("message"));
//pd.show();
Log.e("DialogSHOW", "DialogSHOW "+progress);
}
else if (intent.getExtras().getString("action").equals("hide")){
//pd.dismiss();
finish();
Log.e("DialogHIDE", "DialogHIDE");
}
}