There is an activity which is fired by intents: sets, shows and hides the ProgressDialog. When it sets and shows the activity works fine, but when the hide is called, instead of calling the onDestroy method the onCreate is called. Here is a LogCat when the activity starts:
SHOW_PROGESS
SET_PROGESS
onCreate
onStart
onResume
SET_PROGESS
onPause
DialogSET 15
onResume
SET_PROGESS
onPause
DialogSET 16
onResume
...
The ProgressDialog is set and shown in onNewIntent(Intent intent) method. But when the hide task is called the
pd.dismiss();
finish();
are called and instead of calling onDestroy the onCreate is called:
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
There is a white display without ProgessDialog. After pushing the BACK button the
onPause
onDestroy
are called and then I can see wat I want. How can I solve that I shouldn’t push the BACK button to call the onDestroy again?
The intent is started this way:
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.setAction(intent.ACTION_VIEW);
startActivity(intent);
Thank you!
EDIT:
@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");
}
}
This is what is said on the documentation for
onNewIntent():I believe the problem you are seeing is due to the
finish()call being made inonNewIntent()and then the framework (seeing that it needs to resume your activity as the next step) revives your Activity again.Try moving your code in
onNewIntent()toonResume()instead (maybe adding a flag too to check whether processing is needed), something like: