boolean android.app.Activity.isFinishing()函数使用

这个函数注释:

Check to see whether this activity is in the process of finishing, either because you called finish on it or someone else has requested that it finished. This is often used in onPause to determine whether the activity is simply pausing or completely finishing.

Returns:
If the activity is finishing, returns true; else returns false.
See Also:
finish
判断this Activity是否finish,自己调用或者某种因素请求finish,经常用在onPause函数里面


这次项目中,遇到这个问题,一个activity在finish时候,还有收到广播,结果导致bug

在广播接收器中先判断一下比较保险。或者在onDestroy里面注销广播

private BroadcastReceiver mIntentReceiver = new BroadcastReceiver()
    {
        @Override
        public void onReceive(Context context, Intent intent)
        {
            Log.d(TAG, intent.toString());    
            final String action = intent.getAction();
            
            if(isFinishing())
            {

                  。。。。。。。              

                return;

            }

}


还有遇到一个问题,在activity  finish时候,这时候handler.sendMessage,这时候也会导致bug

这时候最好在finish函数里面removeAllCallbackAndMessage(this)

你可能感兴趣的:(String,action)