开发者

isFinishing is not always accurate in onPause()

I encountered a scenario that isFinishing() returned false, but the activity still exited.

There is Activity Abc in the scenario, which contains a button. When user clicks on the button, Activity Xyz will be started.

Now on Abc activity, I clicked the button on it and the BACK button on the phone almost simultaneously, with the BACK button be a few milliseconds after the touching of the button on Abc. I got the following log message:

09-30 17:32:41.424 I/Abc(20319): [onPause] com.example.Abc@40605928
09-30 17:32:41.424 D/Abc(20319): In onPause, this.isFinishing()=false
09-30 17:32:41.464 I/Xyz(20319): [onCreate] com.example.Xyz@405caf68
09-30 17:32:41.604 I/Xyz(20319): [onStart] com.ex开发者_开发问答ample.Xyz@405caf68
09-30 17:32:41.644 I/Xyz(20319): [onResume]com.example.Xyz@405caf68
09-30 17:32:41.824 I/Abc(20319): [onStop] com.example.Abc@40605928
09-30 17:32:41.884 D/Abc(20319): [onDestroy] com.example.Abc@40605928

From the log above, we can see, the Abc activity was destroyed even when isFinishing() returned false in onPause().

The code I have in onPause() is:

@Override
protected void onPause() {
    super.onPause();

    Log.d(TAG, "[onPause] " + this);
    Log.d(TAG, "In onPause, this.isFinishing()=" + this.isFinishing());
}

Is it a bug in Android?

Thanks.


I think it is a bug in Android OS. When an activity is in onPause(), the OS should ignore the BACK button click on it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜