Skip to content

Commit f50d15d

Browse files
Fix "Duplicate finish request for ActivityRecord" errors
1 parent edcebf1 commit f50d15d

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

app/src/main/java/com/termux/app/TermuxActivity.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ public void onTitleChanged(TerminalSession updatedSession) {
414414
public void onSessionFinished(final TerminalSession finishedSession) {
415415
if (mTermService.mWantsToStop) {
416416
// The service wants to stop as soon as possible.
417-
finish();
417+
finishActivityIfNotFinishing();
418418
return;
419419
}
420420
if (mIsVisible && finishedSession != getCurrentTermSession()) {
@@ -550,7 +550,7 @@ public View getView(int position, View convertView, @NonNull ViewGroup parent) {
550550
});
551551
} else {
552552
// The service connected while not in foreground - just bail out.
553-
finish();
553+
finishActivityIfNotFinishing();
554554
}
555555
} else {
556556
Intent i = getIntent();
@@ -586,7 +586,14 @@ void renameSession(final TerminalSession sessionToRename) {
586586
@Override
587587
public void onServiceDisconnected(ComponentName name) {
588588
// Respect being stopped from the TermuxService notification action.
589-
finish();
589+
finishActivityIfNotFinishing();
590+
}
591+
592+
public void finishActivityIfNotFinishing() {
593+
// prevent duplicate calls to finish() if called from multiple places
594+
if (!TermuxActivity.this.isFinishing()) {
595+
finish();
596+
}
590597
}
591598

592599
@Nullable
@@ -627,7 +634,7 @@ public void onBackPressed() {
627634
if (getDrawer().isDrawerOpen(Gravity.LEFT)) {
628635
getDrawer().closeDrawers();
629636
} else {
630-
finish();
637+
finishActivityIfNotFinishing();
631638
}
632639
}
633640

@@ -989,7 +996,7 @@ public void removeFinishedSession(TerminalSession finishedSession) {
989996
mListViewAdapter.notifyDataSetChanged();
990997
if (mTermService.getSessions().isEmpty()) {
991998
// There are no sessions to show, so finish the activity.
992-
finish();
999+
finishActivityIfNotFinishing();
9931000
} else {
9941001
if (index >= service.getSessions().size()) {
9951002
index = service.getSessions().size() - 1;

0 commit comments

Comments
 (0)