mirror of
https://github.com/emanuele-f/PCAPdroid.git
synced 2026-07-03 21:21:12 +08:00
Fix possible IllegalArgumentException in GeoIP download
The dialog dismiss was called after the view was already destroyed
This commit is contained in:
parent
3618f1e211
commit
a1a7ea317f
@ -42,6 +42,7 @@ public class GeoipSettings extends PreferenceFragmentCompat {
|
||||
private static final String TAG = "GeoipSettings";
|
||||
private Preference mStatus;
|
||||
private Preference mDelete;
|
||||
private AlertDialog mAlertDialog;
|
||||
|
||||
@Override
|
||||
public void onCreatePreferences(@Nullable Bundle savedInstanceState, @Nullable String rootKey) {
|
||||
@ -65,6 +66,15 @@ public class GeoipSettings extends PreferenceFragmentCompat {
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
// See https://stackoverflow.com/questions/22924825/view-not-attached-to-window-manager-crash
|
||||
if(mAlertDialog != null)
|
||||
mAlertDialog.dismiss();
|
||||
|
||||
super.onDestroyView();
|
||||
}
|
||||
|
||||
// NOTE: passing explicit context as this may be called when requireContext would return null
|
||||
private void refreshStatus(Context context) {
|
||||
Date builtDate = Geolocation.getDbDate(context);
|
||||
@ -90,14 +100,15 @@ public class GeoipSettings extends PreferenceFragmentCompat {
|
||||
builder.setTitle(R.string.downloading);
|
||||
builder.setMessage(R.string.download_in_progress);
|
||||
|
||||
final AlertDialog alert = builder.create();
|
||||
alert.setCanceledOnTouchOutside(false);
|
||||
alert.show();
|
||||
mAlertDialog = builder.create();
|
||||
mAlertDialog.setCanceledOnTouchOutside(false);
|
||||
mAlertDialog.show();
|
||||
|
||||
alert.setOnCancelListener(dialogInterface -> {
|
||||
mAlertDialog.setOnCancelListener(dialogInterface -> {
|
||||
Log.i(TAG, "Abort download");
|
||||
executor.shutdownNow();
|
||||
});
|
||||
mAlertDialog.setOnDismissListener(dialog -> mAlertDialog = null);
|
||||
|
||||
// Hold reference to context to avoid garbage collection before the handler is called
|
||||
final Context context = requireContext();
|
||||
@ -108,7 +119,8 @@ public class GeoipSettings extends PreferenceFragmentCompat {
|
||||
if(!result)
|
||||
Utils.showToastLong(context, R.string.download_failed);
|
||||
|
||||
alert.dismiss();
|
||||
if(mAlertDialog != null)
|
||||
mAlertDialog.dismiss();
|
||||
refreshStatus(context);
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user