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;
}
热门推荐
10 八一幼儿祝福语大全简短
11 公司乔迁食堂祝福语简短
12 婚礼结束聚餐祝福语简短
13 儿媳买车妈妈祝福语简短
14 毕业送礼老师祝福语简短
15 同事辞职正常祝福语简短
16 恭贺新婚文案祝福语简短
17 金店立秋祝福语简短英文
18 婆婆高寿祝福语大全简短