Activity isFinishing()判断Activity的状态实例
在Activity中调用finish()或按返回键退出时,若有资源被其他对象引用不能释放(如context被某个单例对象引用或正在线程中被使用),则activity不会被调用onDestory()方法。
isFinishing()可用来判断Activity是否处于活跃状态(false)还是等待回收状态(true)。
isDestroyed()根据源码注释可知,只有onDestroy()方法被调用后它才返回true,因此实际用处不大。
查看源代码中的注释:
/**
*Checktoseewhetherthisactivityisintheprocessoffinishing,
*eitherbecauseyoucalled{@link#finish}onitorsomeoneelse
*hasrequestedthatitfinished.Thisisoftenusedin
*{@link#onPause}todeterminewhethertheactivityissimplypausingor
*completelyfinishing.
*
*@returnIftheactivityisfinishing,returnstrue;elsereturnsfalse.
*
*@see#finish
*/
publicbooleanisFinishing(){
returnmFinished;
}
/**
*Returnstrueifthefinal{@link#onDestroy()}callhasbeenmade
*ontheActivity,sothisinstanceisnowdead.
*/
publicbooleanisDestroyed(){
returnmDestroyed;
}
热门推荐
3 祝福语简短的微信
10 幼儿祝福语大全简短贺卡
11 感谢教官文案祝福语简短
12 鼠年同事祝福语简短创意
13 元旦祝福语 简短独特群发
14 妈咪跟我生日祝福语简短
15 给儿子新婚祝福语简短
16 伴娘祝福语长文案简短
17 恭喜高考完祝福语简短
18 生日祝福语送老公简短