@@ -177,15 +177,14 @@ public void onActivityResult(final int requestCode, final int resultCode,
177177 if ((requestCode == REQUEST_IMPORT_PATH || requestCode == REQUEST_EXPORT_PATH )
178178 && resultCode == Activity .RESULT_OK && data .getData () != null ) {
179179 final File file = Utils .getFileForUri (data .getData ());
180- final String path = file .getAbsolutePath ();
181180
182181 if (requestCode == REQUEST_EXPORT_PATH ) {
183182 exportDatabase (file );
184183 } else {
185184 final AlertDialog .Builder builder = new AlertDialog .Builder (requireActivity ());
186185 builder .setMessage (R .string .override_current_data )
187186 .setPositiveButton (getString (R .string .finish ),
188- (d , id ) -> importDatabase (path ))
187+ (d , id ) -> importDatabase (file ))
189188 .setNegativeButton (android .R .string .cancel ,
190189 (d , id ) -> d .cancel ());
191190 builder .create ().show ();
@@ -214,11 +213,13 @@ private void exportDatabase(final File folder) {
214213 }
215214 }
216215
217- private void importDatabase (final String filePath ) {
216+ private void importDatabase (final File file ) {
217+ final String filePath = file .getAbsolutePath ();
218+
218219 // check if file is supported
219220 if (!ZipHelper .isValidZipFile (filePath )) {
220221 Toast .makeText (getContext (), R .string .no_valid_zip_file , Toast .LENGTH_SHORT )
221- .show ();
222+ .show ();
222223 return ;
223224 }
224225
@@ -239,26 +240,37 @@ private void importDatabase(final String filePath) {
239240
240241 alert .setNegativeButton (android .R .string .no , (dialog , which ) -> {
241242 dialog .dismiss ();
242- // restart app to properly load db
243- System .exit (0 );
243+ finishImport (file );
244244 });
245245 alert .setPositiveButton (getString (R .string .finish ), (dialog , which ) -> {
246246 dialog .dismiss ();
247247 manager .loadSharedPreferences (PreferenceManager
248- .getDefaultSharedPreferences (requireContext ()));
249- // restart app to properly load db
250- System .exit (0 );
248+ .getDefaultSharedPreferences (requireContext ()));
249+ finishImport (file );
251250 });
252251 alert .show ();
253252 } else {
254- // restart app to properly load db
255- System .exit (0 );
253+ finishImport (file );
256254 }
257255 } catch (final Exception e ) {
258256 ErrorActivity .reportUiErrorInSnackbar (this , "Importing database" , e );
259257 }
260258 }
261259
260+ /**
261+ * Save import path and restart system.
262+ *
263+ * @param file The file of the created backup
264+ */
265+ private void finishImport (final File file ) {
266+ if (file .getParentFile () != null ) {
267+ setImportExportDataPath (file .getParentFile ());
268+ }
269+
270+ // restart app to properly load db
271+ System .exit (0 );
272+ }
273+
262274 private void setImportExportDataPath (final File file ) {
263275 final String directoryPath ;
264276 if (file .isDirectory ()) {
0 commit comments