Activity.finish()调用,但活性保持在内存中加载 [英] Activity.finish() called but activity stays loaded in memory

查看:258
本文介绍了Activity.finish()调用,但活性保持在内存中加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在调试器中运行我的应用程序,我得到了主线程和3捆扎线。

When I run my app on the debugger, I get the main thread and 3 binder threads.

在一个按钮,点击我称之为 Activity.finish(),它看起来像它结束该活动作为UI关闭并返回到主屏幕。

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.

然而,在调试器,它仍然显示在主线程和第3捆扎线作为的(运行)

However, in the debugger, it still shows the main thread and 3 binder threads as "(running)".

我百思不得其解,为什么发生这种情况。更是这样,这是导致我的应用程序调用的 Activity.onResume()当我退出应用程序后重新运行。

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()

任何有关此帮助或建议,很多AP preciated!

Any help or advice regarding this is much appreciated!

推荐答案

当你的应用程序离开主内存,操作系统确实你不用管。仔细看看<一href="http://developer.android.com/reference/android/app/Activity.html#finish%28%29">Activity.finish...

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

打电话当你的活动做   和应关闭。该   ActivityResult传播回   凡经推出,你   onActivityResult()。

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

请注意这是只字未提内存。至于调用Activity.onResume,这正是你所期望的生命周期;这的记住onResume不只是所谓的后一份简历,但即使在应用程序的onCreate后第一次启动。

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]是完全等同于打后退按钮。

这篇关于Activity.finish()调用,但活性保持在内存中加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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