Remove option to immediately commit pref changes on import

System is now not restarted with `System.exit(0)`.
Instead it is done properly by finishing the activity and restarting the activity. This allows preference changes which are queued up asynchronously through `apply` to be applied.
This commit is contained in:
XiangRongLin 2021-06-20 09:17:55 +02:00
parent 74ad488f4a
commit 9767e98e50
1 changed files with 5 additions and 10 deletions

View File

@ -199,7 +199,7 @@ public class ContentSettingsFragment extends BasePreferenceFragment {
.getDefaultSharedPreferences(requireContext());
manager.exportDatabase(preferences, file);
saveLastImportExportDataUri(false); // save export path only on success
saveLastImportExportDataUri(); // save export path only on success
Toast.makeText(getContext(), R.string.export_complete_toast, Toast.LENGTH_SHORT).show();
} catch (final Exception e) {
ErrorActivity.reportUiErrorInSnackbar(this, "Exporting database", e);
@ -252,8 +252,8 @@ public class ContentSettingsFragment extends BasePreferenceFragment {
* Save import path and restart system.
*/
private void finishImport() {
// save import path only on success; save immediately because app is about to exit
saveLastImportExportDataUri(true);
// save import path only on success
saveLastImportExportDataUri();
// restart app to properly load db
NavigationHelper.restartApp(requireActivity());
}
@ -263,16 +263,11 @@ public class ContentSettingsFragment extends BasePreferenceFragment {
return isBlank(path) ? null : Uri.parse(path);
}
private void saveLastImportExportDataUri(final boolean immediately) {
private void saveLastImportExportDataUri() {
if (lastImportExportDataUri != null) {
final SharedPreferences.Editor editor = defaultPreferences.edit()
.putString(importExportDataPathKey, lastImportExportDataUri.toString());
if (immediately) {
// noinspection ApplySharedPref
editor.commit(); // app about to be restarted, commit immediately
} else {
editor.apply();
}
editor.apply();
}
}
}