简体   繁体   English

Android:对话框触发onResume

[英]Android: Dialog triggered onResume

I am experiencing a weird behavior in my app. 我的应用程序出现奇怪的行为。

I have an Activity with a ListView. 我有一个带有ListView的Activity。 When you click on an item in the ListView, a TimePickerDialog is shown. 当您单击ListView中的项目时,将显示一个TimePickerDialog。

If I hit the home button after closing the dialog, and then reload the app, the TimePickerDialog is shown automatically again. 如果我在关闭对话框后按了主页按钮,然后重新加载了应用程序,则将再次自动显示TimePickerDialog。

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! 在TimePickerFragment的构造函数中,它不会被解雇! 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. 多亏nandeesh的回答,我才得以弄清楚如何解决该问题。

Since my dialog was managed, I had to call the dismissAllowingStateLoss() method on my dialog instance. 由于对话框是受管的,因此必须在对话框实例上调用dismissAllowingStateLoss()方法。

Works like a charm now. 现在就像魅力一样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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