0

In case of network unavailability, storing some important information into the sqlite database and file on internal storage. When network available, it will sync to the server in background.

But when a user performs Clear Data, it deletes database and file stored on internal storage. Because of that, I am facing lot much data loss.

I already search on, how to catch clear data event and related below questions:

Also I can not store that data on external storage, because it can easily access by user using File managers and they can delete it manually.

So my questions are:

  1. How I can prevent my offline data from deleting?

  2. Is there any way to save offline data at secure place and access it only through application?

Anil Ravsaheb Ghodake
  • 1,587
  • 2
  • 27
  • 45

1 Answers1

4

How I can prevent my offline data from deleting?

You can't. It's the user's device, not yours, and so it is not your data — it is the user's data. The user can do what the user wants.

Is there any way to save offline data at secure place and access it only through application?

Internal storage prevents direct access to your files by the user or by other apps. It does not prevent the user from getting rid of those files, either through "clear data" or by uninstalling your app.

Can we disable, Clear Data event for my application?

Not really. On some versions of Android, you can get control when the user clicks that button. However:

  • Do not assume that all devices will support this
  • Device manufacturers might provide other means for the user to clear the data
  • The user can still uninstall and reinstall the app, which will clear the data
CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Is there any mechanism or event provide by android system, to avoid data loss in case of network unavailability? Or Please can you suggest me possible ways to handle this case? – Anil Ravsaheb Ghodake Apr 09 '19 at 12:19
  • 1
    @AnilRGhodake: If the user chooses to clear data, that is the user's choice. The user has to accept responsibility for that choice, which will include possible data loss if they clear data that has not been synchronized to the server. If you do not want this behavior, do not store data locally, and have your app refuse to do anything if there is no server connection. – CommonsWare Apr 09 '19 at 12:25