Android 启动器“OnDestroy"被调用两次 [英] Android Launcher "OnDestroy" gets called twice

查看:42
本文介绍了Android 启动器“OnDestroy"被调用两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

重现步骤:

  1. 在调试模式下运行在 Xamarin.Android 中实现的启动器.
  2. 在 OnDestroy 方法覆盖上放置一个断点.
  3. 打开 Google 地图.开始导航
  4. 按主页按钮将尝试打开启动器用户界面备份.

一旦我这样做,OnDestroy 中的断点就会命中,然后是OnCreate"中的断点.然后再一次OnDestroy"后跟OnCreate".

As soon as I do that, the breakpoint in OnDestroy hits followed by breakpoint in "OnCreate" and then once more "OnDestroy" followed by "OnCreate".

这导致整个启动器实际上不仅重启一次,而且两次.

It is causing the whole launcher to practically restart not only once, but twice.

我什至将 MainActivity OnCreate 中的每一段代码都注释掉了,里面什么都没有,只是为了确保这不是我的代码,但它仍然是完全相同的行为.

I even commented out every single piece of code from MainActivity OnCreate to have nothing in there just to make sure that is not my code, but it is still the exact same behavior.

理想情况下,我不会看到OnDestroy"称呼.任何想法...

Ideally, I would to see no "OnDestroy" call. Any thoughts...

推荐答案

经过多次尝试和错误后找到了答案.将 ConfigChanges.UiMode 标志添加到您的 MainActivity 类的 ConfigurationChanges 属性,这解决了问题,并且 Launcher 不再重新启动.

Found the answer after many trials and errors. Add ConfigChanges.UiMode flag to the ConfigurationChanges attribute for your MainActivity class, and this solves the problem, and Launcher does not restart anymore.

这篇关于Android 启动器“OnDestroy"被调用两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆