[英]onCreate not being called in debug build?
I found my app behavior differently between debug build vs release build:我发现我的应用程序在调试版本和发布版本之间的行为不同:
In debug, when re-open the app after home button is pressed, onResume is called.在调试中,当按下主页按钮后重新打开应用程序时,会调用 onResume。 (onCreate is NOT called).
(不调用 onCreate)。
In production (release build), re-open the app calls onCreate first when home button is pressed.在生产(发布版本)中,按下主页按钮时,首先重新打开应用程序调用 onCreate。
The difference introduces a bug because I set a flag in onCreate.差异引入了一个错误,因为我在 onCreate 中设置了一个标志。 Question: which one is the right behavior?
问题:哪一种是正确的行为? Am I able to make my release build work the same way as the debug build (without onCreate being called when re-open the app after home button is pressed)?
我是否能够使我的发布版本以与调试版本相同的方式工作(在按下主页按钮后重新打开应用程序时不会调用 onCreate)?
In debug, when re-open the app after home button is pressed, onResume is called.
在调试中,当按下主页按钮后重新打开应用程序时,会调用 onResume。 (onCreate is NOT called).
(不调用 onCreate)。
Settings -> Developer Options -> aplication section.设置 -> 开发者选项 -> 应用程序部分。 "Do not keep activities" - default is off.
“不保留活动” - 默认关闭。
I suspect " when re-open the app after home button is pressed " your activity is in background only and normally shouldn't be destroyed, hence shouldn't have called the onCreate.我怀疑“在按下主页按钮后重新打开应用程序时”您的活动仅在后台运行,通常不应被销毁,因此不应调用 onCreate。 So the debug mode is working as expected.
所以调试模式按预期工作。
In release mode you have something which kills your activity, when is he in a background.在发布模式下,你有什么东西会杀死你的活动,他什么时候在后台。 Can be a part of the code, can be a missing translation or an unhanded exception somewhere, you should get an ANR or "aplication exited unexpectedly"
可以是代码的一部分,可以是缺少翻译或某处未处理的异常,您应该得到 ANR 或“应用程序意外退出”
I would suggest to try some logs int a file or and check what happens the in release mode.我建议在文件中尝试一些日志,或者检查在发布模式下会发生什么。
Can be another app - even from Android OS -, which detect your application went to background so it will kill it to make more room in memory, but he doesn't kill the Debug apps..可以是另一个应用程序 - 甚至来自 Android 操作系统 - 检测您的应用程序进入后台,因此它会杀死它以在内存中腾出更多空间,但他不会杀死调试应用程序..
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.