8

I have created Sqlite database in app. when I clear data from settings->applications->manage applications the Sqlite db removed. any suggestions to keep sqlite database as it is.

Pankaj Kharche
  • 1,329
  • 4
  • 15
  • 37
  • http://stackoverflow.com/questions/7806629/why-sqlite-database-cleared-on-clearing-data-of-application-from-application-man – Nermeen May 10 '13 at 06:46
  • I have read this post. Run one example provided in this post. It saving data which is inserted in oncreate method of databasehelper class. after running the app I have inserted records into db, then again clear data my inserted records was deleted. @Nunu – Pankaj Kharche May 10 '13 at 07:01
  • yes, as clearing data means deleting the db also..then when the app starts and do not find the db, it will create it again and insert the records existing in the oncreate – Nermeen May 10 '13 at 07:04
  • but what about the records inserted while app is running. can I not stored them. @Nunu – Pankaj Kharche May 10 '13 at 08:03
  • you stored them but by clearing data you lost them – Nermeen May 10 '13 at 08:06
  • ok fine... thanks for you response.@Nunu – Pankaj Kharche May 10 '13 at 08:23

3 Answers3

15

When you press Clear Data from the Android application manager its supposed to remove everything related to the app such as preferences, databases, caches etc the only thing that gets left is the app so when you re-launch it behaves as if it was just installed.

If you want to allow the user to clear the data but keep the database then there should be an option in the menu that removes the shared preferences but doesn't do anything with the database.

Hope this helps.

Boardy
  • 35,417
  • 104
  • 256
  • 447
  • Is the "cleaner apps" that free spaces can delete databases? – Pavel Poley Apr 04 '21 at 09:33
  • I don't think so, the cleaner apps I believe just clear files that aren't actually in use anymore, such a temporary files, update files etc. An apps own files such as its database can only be managed by the app itself or by going through the Android application manager to clear it as far as I am aware. The cleaner apps might have the ability to clear app data, but it won't be configurable, it will be the same action as clear data through Android application manager I believe – Boardy Apr 06 '21 at 07:42
1

Android's SQLite is intented for local app data storage. When you opt to wipe your app's data, this data is wiped (as expected).

If you want to persist DB data, look into external storage (eg. the late Parse.com, or MS's Azure). You'll be making network calls, your local data will still be wiped, and you'll need to have a way to link your app back up with the external data post-local-wipe (eg. logging in) but your external data will survive an app data clear.

The "linking up" part can be mitigated as well depending on your use case, eg. Google Play Games' data services is tied to your Google Play id and will resync after an app wipe.

Tom
  • 6,946
  • 2
  • 47
  • 63
0

Why would you want to keep the data when the user wants to clear everything. It is not suggested you keep the db.

I would suggest you use the sd card to store images/text files with the adequate permission from the user.

Aditya Kushwaha
  • 839
  • 6
  • 12