Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to avoid Duplicate finish request for ActivityRecord

From LoginActivity after successful login app goes to the MainActivity. When I click the back button i get this warning.

W/ActivityManager: Duplicate finish request for ActivityRecord

And when I start the app again LoginActivity is called again.

After successful login I call

Intent intent = new Intent(this, HomeActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | IntentCompat.FLAG_ACTIVITY_CLEAR_TASK);
    startActivity(intent);
    finish();

The problem is only in the release build.

like image 229
user1382802 Avatar asked Sep 16 '25 15:09

user1382802


1 Answers

If this is not related to back press, maybe you have more than one finish() call from different places. Just check if activity is finishing or not, if yes then skip the 2nd call.

if (!YourActivity.this.isFinishing()) {
    finish(); 
}
like image 68
Allen Chan Avatar answered Sep 18 '25 05:09

Allen Chan