RAAAAM
RAAAAM

Reputation: 3380

How to delete the data while re-install the app

Thanks for previous replies,

is it possible to delete the stored content from sqlite once re-install the application. I am storing data in database, once i re-install the same app again, the previous data still stores in sqlite. i want to delete the stored content while re install the app. i am not sure about this.

Upvotes: 4

Views: 8444

Answers (6)

RAAAAM
RAAAAM

Reputation: 3380

Thanks for all replies,

I maintain the Version code for all the builds, once i re-install the application, i check the version, if i found the version changes, i simply remove the DB. this case only applicable for overriding the install of APk(ie without un-installing the application). When we made a uninstall, the internal data and sqlite for the application ill automatically deleted.

Upvotes: 1

Mohammad Ersan
Mohammad Ersan

Reputation: 12444

application SharedPreferance is deleted on un-installing the app, so save a boolean to determine if the application is running for the first time or not.

Upvotes: 0

Sparky
Sparky

Reputation: 8477

When you delete the app, then the database should be deleted too. Unless you go to some trouble to keep it. If you simply update the app, then the data should be kept. If you need to delete the data upon reinstall, try this:

Every time you start an Activity, call PackageManager.getPackageInfo() and check lastUpdateTime. Compare it with a time stamp that you store in the database or a shared preference. If lastUpdateTime is newer, delete the your database.

Upvotes: 0

Kristopher Micinski
Kristopher Micinski

Reputation: 7672

This seems like a hack and maybe not the actual answer, but can you -- with each new version of your app -- increment an identifier (from 10 to 11) in the code and then check against a stored preferences containing that identifier. If you have a constant in your code that is higher than the identifier stored on the previous device, then you can clear the database to whatever you think its state should be. Then with each new released version of the app you increment this number..

Edit: In API level 9 and higher, you can -- whenever your app starts up -- write the date in which the app was installed (see here for an explanation on how to find the install date). If you check that it was installed after the date which is written, kill the data!

Upvotes: 1

petey
petey

Reputation: 17140

Read here : Detect Android app upgrade and set Application class boolean for show/hide of EULA

Create a UpgradeBroadcastReceiver of your own that will run the delete instructions you want and register it in your manifest file.

Upvotes: 0

Probably Sleepin
Probably Sleepin

Reputation: 165

sqlite databases are stored as files on your file system, to delete the data. You just need to delete the file.

What you'd want to do is setup some way of detecting if the app is being run for the first time, if this is the first time the app has been run then check the database exists, if it does delete it. Then recreate the database as empty.

Or you could go through and remove all the data in each table/drop each table in the database on the first run if the database exists.

Upvotes: 0

Related Questions