Activity.finish() 已调用,但 Activity 仍加载在内存中

发布于 2024-10-10 22:48:10 字数 455 浏览 3 评论 0原文

当我在调试器上运行我的应用程序时,我得到主线程和 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

泅人 2024-10-17 22:48:10

您无法控制应用程序何时离开主内存,而是操作系统可以控制。仔细看看 Activity.finish...

当你的活动完成时调用这个
并且应该关闭。这
ActivityResult 被传播回
无论谁通过以下方式启动您
onActivityResult()。

请注意,这并没有提到内存。至于调用 Activity.onResume,这正是您对生命周期的期望;请记住,onResume 不仅会在恢复后调用,甚至在 onCreate 之后首次启动应用程序时也会调用。

虽然不完全符合您的要求,但我建议您阅读 这篇关于退出的文章按钮接着说了一些非常重要的事情

[Activity.finish] 与点击后退按钮完全相同。

You don't control when your app leaves main memory, the OS does. Look closely at Activity.finish...

Call this when your activity is done
and should be closed. The
ActivityResult is propagated back to
whoever launched you via
onActivityResult().

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

[Activity.finish] is exactly equivalent to hitting the back button.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文