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

来源:互联网 发布:服务器返回数据错误 编辑:程序博客网 时间:2024/05/20 11:48

这个函数注释:

Check to see whether this activity is in the process of finishing, either because you calledfinish on it or someone else has requested that it finished. This is often used inonPause 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)

原创粉丝点击