Calling finish() doesn't finish the activity
Asked Answered
I

2

7

I want to finish my activity when it pauses for specific reasons. Up till recently my code was working perfectly but recently the finish() method stopped doing its job for some reason. Also, when the finish() method is called, I get the following LogCatmessage:

12-31 18:01:23.445: W/ActivityManager(481): Duplicate finish request for ActivityRecord{42465370 u11 "myapplicationpackage"}

Could someone help me out with this?

OnPause() method

@Override
protected void onPause() {
    super.onPause();
    finish();
}
Illtempered answered 1/1, 2013 at 2:14 Comment(2)
calling finish() inside onPause is not a good idea. you can call finish() at "Specific reasons" occurrences. May in event handling etc.Reproductive
You might want to take a look at this code which shows you the condition at which "Duplicate Finish Request happens". grepcode.com/file/repository.grepcode.com/java/ext/…Donne
F
12

You can check if your activity is finishing already by calling if (isFinishing()){}, and calling finish only if it is not. Alternatively you might want to specify android:noHistory="true" on your activity in manifest file, which will actually finish your activity once user navigates away from it.

Footway answered 1/1, 2013 at 2:56 Comment(1)
#18020705Donne
S
-7

You most possibly have duplicate copies of an activity running. I suggest make all activities under one parent, and use

finishall()
Sam answered 1/1, 2013 at 2:37 Comment(1)
There is no method finishall.Expectation

© 2022 - 2024 — McMap. All rights reserved.