简体   繁体   中英

Android: Dialog triggered onResume

I am experiencing a weird behavior in my app.

I have an Activity with a ListView. When you click on an item in the ListView, a TimePickerDialog is shown.

If I hit the home button after closing the dialog, and then reload the app, the TimePickerDialog is shown automatically again.

Now, I don't know why this behavior happens. I have logged messages at different points in the app to try to determine how it is triggered but to no avail.

I even added this line:

Log.d("TEST", "TEST");

inside the constructor of the TimePickerFragment and it is not getting fired! Yet the dialog is showing up!

What is going on here?

The activity will save the state. So it will also save state for managed dialogs. When you come back, it will restore. Since it is already created, constructor wont be called. As far as i know if you do not let the activity manage the dialogs, this behavior will not occur

Thanks to nandeesh's answer, I was able to figure out how to fix that behavior.

Since my dialog was managed, I had to call the dismissAllowingStateLoss() method on my dialog instance.

Works like a charm now.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM