Skip to content

Commit

Permalink
Fix "Duplicate finish request for ActivityRecord" errors
Browse files Browse the repository at this point in the history
  • Loading branch information
agnostic-apollo committed Feb 26, 2021
1 parent edcebf1 commit f50d15d
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions app/src/main/java/com/termux/app/TermuxActivity.java
Expand Up @@ -414,7 +414,7 @@ public void onTitleChanged(TerminalSession updatedSession) {
public void onSessionFinished(final TerminalSession finishedSession) {
if (mTermService.mWantsToStop) {
// The service wants to stop as soon as possible.
finish();
finishActivityIfNotFinishing();
return;
}
if (mIsVisible && finishedSession != getCurrentTermSession()) {
Expand Down Expand Up @@ -550,7 +550,7 @@ public View getView(int position, View convertView, @NonNull ViewGroup parent) {
});
} else {
// The service connected while not in foreground - just bail out.
finish();
finishActivityIfNotFinishing();
}
} else {
Intent i = getIntent();
Expand Down Expand Up @@ -586,7 +586,14 @@ void renameSession(final TerminalSession sessionToRename) {
@Override
public void onServiceDisconnected(ComponentName name) {
// Respect being stopped from the TermuxService notification action.
finish();
finishActivityIfNotFinishing();
}

public void finishActivityIfNotFinishing() {
// prevent duplicate calls to finish() if called from multiple places
if (!TermuxActivity.this.isFinishing()) {
finish();
}
}

@Nullable
Expand Down Expand Up @@ -627,7 +634,7 @@ public void onBackPressed() {
if (getDrawer().isDrawerOpen(Gravity.LEFT)) {
getDrawer().closeDrawers();
} else {
finish();
finishActivityIfNotFinishing();
}
}

Expand Down Expand Up @@ -989,7 +996,7 @@ public void removeFinishedSession(TerminalSession finishedSession) {
mListViewAdapter.notifyDataSetChanged();
if (mTermService.getSessions().isEmpty()) {
// There are no sessions to show, so finish the activity.
finish();
finishActivityIfNotFinishing();
} else {
if (index >= service.getSessions().size()) {
index = service.getSessions().size() - 1;
Expand Down

0 comments on commit f50d15d

Please sign in to comment.