Activity.finish() 已调用,但 Activity 仍加载在内存中
当我在调试器上运行我的应用程序时,我得到主线程和 3 个活页夹线程。
单击按钮时,我调用 Activity.finish(),这看起来会在 UI 关闭并返回主屏幕时结束活动。
但是,在调试器中,它仍然将主线程和 3 个绑定器线程显示为“(正在运行)”。
我很困惑为什么会发生这种情况。更重要的是,当我退出应用程序后再次运行它时,它会导致我的应用程序调用 Activity.onResume() 。
我目前在 Activity 中重写这些方法,但我在每个方法中调用适当的超级函数:
- onDestroy()
- onPause()
- onResume()
- onSaveInstanceState()
非常感谢任何有关此问题的帮助或建议!
When I run my app on the debugger, I get the main thread and 3 binder threads.
On a button click I call Activity.finish(), which looks like it ends the activity as the UI closes and goes back to the home screen.
However, in the debugger, it still shows the main thread and 3 binder threads as "(running)".
I am baffled to why this is happening. Even more so, it is causing my app to call Activity.onResume() when I run it again after exiting the app.
I currently override these methods in the Activity, but I call the appropriate super functions in each one:
- onDestroy()
- onPause()
- onResume()
- onSaveInstanceState()
Any help or advice regarding this is much appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您无法控制应用程序何时离开主内存,而是操作系统可以控制。仔细看看 Activity.finish...
请注意,这并没有提到内存。至于调用 Activity.onResume,这正是您对生命周期的期望;请记住,onResume 不仅会在恢复后调用,甚至在 onCreate 之后首次启动应用程序时也会调用。
虽然不完全符合您的要求,但我建议您阅读 这篇关于退出的文章按钮接着说了一些非常重要的事情
You don't control when your app leaves main memory, the OS does. Look closely at Activity.finish...
Note that is says nothing about memory. As to calling Activity.onResume, that's exactly what you would expect for the lifecycle; remeber that onResume is not just called after a resume but even when the app is first launched after onCreate.
While not exactly what you asked I suggest you read this article about exit buttons which goes on to say something very important