55import static app .revanced .extension .shared .requests .Route .Method .GET ;
66
77import android .annotation .SuppressLint ;
8+ import android .app .Activity ;
89import android .app .Dialog ;
910import android .app .ProgressDialog ;
1011import android .content .Context ;
@@ -125,6 +126,8 @@ private String createDialogHtml(WebLink[] aboutLinks) {
125126
126127 {
127128 setOnPreferenceClickListener (pref -> {
129+ Context context = pref .getContext ();
130+
128131 // Show a progress spinner if the social links are not fetched yet.
129132 if (!AboutLinksRoutes .hasFetchedLinks () && Utils .isNetworkConnected ()) {
130133 // Show a progress spinner, but only if the api fetch takes more than a half a second.
@@ -137,17 +140,18 @@ private String createDialogHtml(WebLink[] aboutLinks) {
137140 handler .postDelayed (showDialogRunnable , delayToShowProgressSpinner );
138141
139142 Utils .runOnBackgroundThread (() ->
140- fetchLinksAndShowDialog (handler , showDialogRunnable , progress ));
143+ fetchLinksAndShowDialog (context , handler , showDialogRunnable , progress ));
141144 } else {
142145 // No network call required and can run now.
143- fetchLinksAndShowDialog (null , null , null );
146+ fetchLinksAndShowDialog (context , null , null , null );
144147 }
145148
146149 return false ;
147150 });
148151 }
149152
150- private void fetchLinksAndShowDialog (@ Nullable Handler handler ,
153+ private void fetchLinksAndShowDialog (Context context ,
154+ @ Nullable Handler handler ,
151155 Runnable showDialogRunnable ,
152156 @ Nullable ProgressDialog progress ) {
153157 WebLink [] links = AboutLinksRoutes .fetchAboutLinks ();
@@ -164,7 +168,17 @@ private void fetchLinksAndShowDialog(@Nullable Handler handler,
164168 if (handler != null ) {
165169 handler .removeCallbacks (showDialogRunnable );
166170 }
167- if (progress != null ) {
171+
172+ // Don't continue if the activity is done. To test this tap the
173+ // about dialog and immediately press back before the dialog can show.
174+ if (context instanceof Activity activity ) {
175+ if (activity .isFinishing () || activity .isDestroyed ()) {
176+ Logger .printDebug (() -> "Not showing about dialog, activity is closed" );
177+ return ;
178+ }
179+ }
180+
181+ if (progress != null && progress .isShowing ()) {
168182 progress .dismiss ();
169183 }
170184 new WebViewDialog (getContext (), htmlDialog ).show ();
0 commit comments