Fix "Duplicate finish request for ActivityRecord" errors

This commit is contained in:
agnostic-apollo
2021-02-26 17:09:04 +05:00
parent edcebf1336
commit f50d15d353

View File

@@ -414,7 +414,7 @@ public final class TermuxActivity extends Activity implements ServiceConnection
public void onSessionFinished(final TerminalSession finishedSession) { public void onSessionFinished(final TerminalSession finishedSession) {
if (mTermService.mWantsToStop) { if (mTermService.mWantsToStop) {
// The service wants to stop as soon as possible. // The service wants to stop as soon as possible.
finish(); finishActivityIfNotFinishing();
return; return;
} }
if (mIsVisible && finishedSession != getCurrentTermSession()) { if (mIsVisible && finishedSession != getCurrentTermSession()) {
@@ -550,7 +550,7 @@ public final class TermuxActivity extends Activity implements ServiceConnection
}); });
} else { } else {
// The service connected while not in foreground - just bail out. // The service connected while not in foreground - just bail out.
finish(); finishActivityIfNotFinishing();
} }
} else { } else {
Intent i = getIntent(); Intent i = getIntent();
@@ -586,7 +586,14 @@ public final class TermuxActivity extends Activity implements ServiceConnection
@Override @Override
public void onServiceDisconnected(ComponentName name) { public void onServiceDisconnected(ComponentName name) {
// Respect being stopped from the TermuxService notification action. // 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 @Nullable
@@ -627,7 +634,7 @@ public final class TermuxActivity extends Activity implements ServiceConnection
if (getDrawer().isDrawerOpen(Gravity.LEFT)) { if (getDrawer().isDrawerOpen(Gravity.LEFT)) {
getDrawer().closeDrawers(); getDrawer().closeDrawers();
} else { } else {
finish(); finishActivityIfNotFinishing();
} }
} }
@@ -989,7 +996,7 @@ public final class TermuxActivity extends Activity implements ServiceConnection
mListViewAdapter.notifyDataSetChanged(); mListViewAdapter.notifyDataSetChanged();
if (mTermService.getSessions().isEmpty()) { if (mTermService.getSessions().isEmpty()) {
// There are no sessions to show, so finish the activity. // There are no sessions to show, so finish the activity.
finish(); finishActivityIfNotFinishing();
} else { } else {
if (index >= service.getSessions().size()) { if (index >= service.getSessions().size()) {
index = service.getSessions().size() - 1; index = service.getSessions().size() - 1;