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;
}