Losing data when using public external storage and rebooting device


We are observing a strange problem: When rebooting a device we are loosing all the data that was saved since the previous reboot.

The problem seems to happen only under the following conditions:

  • When running on a Blackview BV6000 device with Android 7.0. We have not seen this problem on any other device.
  • When saving the Realm database on public external storage (Environment.getExternalStorageDirectory()). We do not get the problem when the realm database is saved at the default location (private internal storage).

We have created a small test app to demonstrate the problem. The APK and source code can be downloaded here:

Steps to reproduce the problem:

  • Run the app
  • Select “Public External” storage.
  • Enter a description like “test1” then click Save.
  • Reboot device.
  • First time you reboot it will be fine (because it had to create the database file first).
  • Now enter “test2” and Save.
  • Reboot the device again.
  • Now you will see the problem (DB has “test1” instead of “test2”).
  • From now on every time you reboot the device it will lose the latest value that you have saved in the database.