From ef42416c91fc8c0c597b5306f95867e8f6d40466 Mon Sep 17 00:00:00 2001 From: FerdyRod Date: Tue, 4 Jun 2024 12:41:10 +0200 Subject: [PATCH] prevent app crash when delete local data dialog in shown and device is rotated --- .../dhis2/usescases/settings/SyncManagerFragment.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/dhis2/usescases/settings/SyncManagerFragment.java b/app/src/main/java/org/dhis2/usescases/settings/SyncManagerFragment.java index ab27a4d59b..01123525d9 100644 --- a/app/src/main/java/org/dhis2/usescases/settings/SyncManagerFragment.java +++ b/app/src/main/java/org/dhis2/usescases/settings/SyncManagerFragment.java @@ -119,6 +119,8 @@ public void onReceive(Context context, Intent intent) { private boolean dataWorkRunning; private SettingItem settingOpened = null; + private AlertDialog deleteLocalDataDialog; + public SyncManagerFragment() { // Required empty public constructor } @@ -232,6 +234,9 @@ public void onResume() { @Override public void onPause() { super.onPause(); + if (deleteLocalDataDialog != null && deleteLocalDataDialog.isVisible()) { + deleteLocalDataDialog.dismiss(); + } context.unregisterReceiver(networkReceiver); presenter.dispose(); } @@ -272,7 +277,7 @@ private void saveTimeMeta(int time) { @Override public void deleteLocalData() { - new AlertDialog( + deleteLocalDataDialog = new AlertDialog( getString(R.string.delete_local_data), getString(R.string.delete_local_data_message), null, @@ -291,7 +296,8 @@ public void deleteLocalData() { presenter.deleteLocalData(); return null; }) - ).show(requireActivity().getSupportFragmentManager()); + ); + deleteLocalDataDialog.show(requireActivity().getSupportFragmentManager()); } @Override