Some users report data loss.

After a long time, when the application starts without any problems, I received a report form in which the user reported that the data / photos that were saved were lost. That is, it can work at the initial stage, but at a later stage, the content disappears. I can’t duplicate the problem, so I’m trying to figure out if I can β€œguess” it.

First of all, make sure that I do not save the data in a way that is not possible for recent versions of Android. This is how I save data now:

...

Try first

File storage_files_dir_file = ctx.getExternalFilesDir("");
if (storage_files_dir_file.exists() == false) {
  return false;
}
// ... some code here prepping content
os = new FileOutputStream(path_final,true);
// ... some code here writing content
MediaScannerConnection.scanFile(ctx, new String[] {s}, null, null);
return true

If the above value returns a false switch on

File storage_files_dir_file = ctx.getFilesDir();
if (storage_files_dir_file.exists() == false) {
  return false;
}
// ... some code here prepping content
os = new FileOutputStream(path_final,true);
// ... some code here writing content
return true

...

If this is a problem with the file, I see the following possibilities:

  • Problem with data access?
  • Are saved files deleted by Android?
  • ?
  • , SD- ?
  • , , SD- ?
  • ?
  • : Android 8 ?
  • : Android 8 +, . , .

, , , , , , .

...

2017 .

, Android 8 Oreo. , , ? + , , , -? : ? ?

- , Android 6 Android 7, , Android.

...

- , , ? , .

+4

Source: https://habr.com/ru/post/1696064/


All Articles