是的onPause保证当活动不再运行被称为? [英] Is onPause guaranteed to be called when an Activity is no longer running?

查看:107
本文介绍了是的onPause保证当活动不再运行被称为?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建一个活动一个新的线程,我靠的onPause()中断线程。如果我的应用程序崩溃,或以某种方式活动不再存在,我想线程被杀死。

时的活动/ Fragment.onPause()保证当一个活动不再运行,被称为?如果没有,我怎么能保证有问题的线程被杀害?


解决方案

  

如果我的应用程序崩溃


的onPause()这里不叫,但你的整个应用过程中不再存在,包括你创建的所有线程这不应该打扰你(UI或其他)。


  

活动在某种程度上将不复存在


的onPause()只要您的活动被转移到从前景,这是每一个可以想象的方式,你的活动可以关闭完成的背景将被调用,除非你的应用程序崩溃。但是,正如我上面提到的,应用程序崩溃也将在默认情况下杀死你的线程。

的onPause()基本上是所谓的,只要您的活动是在前景不再。您的活动可能还活着,并在内存中后,的onPause()被调用,但没有的情况,我能想到的,你的活动还活着,并在后台没有的onPause()被调用。

I create a new thread in an activity and I rely on onPause() to interrupt the thread. If my app crashes, or the Activity somehow ceases to exist, I want the thread to be killed.

Is Activity/Fragment.onPause() guaranteed to be called when an Activity is no longer running? If not, how can I guarantee the thread in question is killed?

解决方案

If my app crashes

onPause() is not called here, but this shouldn't bother you as your entire app process ceases to exist, inclusive of all threads you have created (UI or otherwise).

Activity somehow ceases to exist

onPause() will be called whenever your Activity is moved to the background from the foreground, which is done in every conceivable way in which your Activity can be shut down, except for your app crashing. However, as I mentioned above, the app crashing will also by default kill your thread.

onPause() is essentially called whenever your Activity is no longer in the foreground. Your Activity may still be alive and in memory after onPause() has been called, but there is no scenario which I can think of in which your Activity is alive and in the background without onPause() being called.

这篇关于是的onPause保证当活动不再运行被称为?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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