@@ -414,7 +414,7 @@ public void onTitleChanged(TerminalSession updatedSession) {
414
414
public void onSessionFinished (final TerminalSession finishedSession ) {
415
415
if (mTermService .mWantsToStop ) {
416
416
// The service wants to stop as soon as possible.
417
- finish ();
417
+ finishActivityIfNotFinishing ();
418
418
return ;
419
419
}
420
420
if (mIsVisible && finishedSession != getCurrentTermSession ()) {
@@ -550,7 +550,7 @@ public View getView(int position, View convertView, @NonNull ViewGroup parent) {
550
550
});
551
551
} else {
552
552
// The service connected while not in foreground - just bail out.
553
- finish ();
553
+ finishActivityIfNotFinishing ();
554
554
}
555
555
} else {
556
556
Intent i = getIntent ();
@@ -586,7 +586,14 @@ void renameSession(final TerminalSession sessionToRename) {
586
586
@ Override
587
587
public void onServiceDisconnected (ComponentName name ) {
588
588
// 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
+ }
590
597
}
591
598
592
599
@ Nullable
@@ -627,7 +634,7 @@ public void onBackPressed() {
627
634
if (getDrawer ().isDrawerOpen (Gravity .LEFT )) {
628
635
getDrawer ().closeDrawers ();
629
636
} else {
630
- finish ();
637
+ finishActivityIfNotFinishing ();
631
638
}
632
639
}
633
640
@@ -989,7 +996,7 @@ public void removeFinishedSession(TerminalSession finishedSession) {
989
996
mListViewAdapter .notifyDataSetChanged ();
990
997
if (mTermService .getSessions ().isEmpty ()) {
991
998
// There are no sessions to show, so finish the activity.
992
- finish ();
999
+ finishActivityIfNotFinishing ();
993
1000
} else {
994
1001
if (index >= service .getSessions ().size ()) {
995
1002
index = service .getSessions ().size () - 1 ;
0 commit comments