How to delete the data while re-install the app - android

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.

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!

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.

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.

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.

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.

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.

Related

Preserving SQLite db data on App Update/Reinstall Rollout Xamarin

I have Xamarin.Forms shared project that I am testing on Android phone currently.
The sqlite db is stored in System.Environment.SpecialFolder.Personal as of now.
I want to make sure that user input data stored in db is preserved:
1 upon each next upgrade I am planning for an app, as well as
2 In additional situation where user removes his app totally and makes a fresh install
(I guess these are two totally different situations, but I might be wrong)
I would like to know whether an update of an App via Google Play Store Update will overwrite db file too, therefore all data be lost? Or will the data be preserved?
What would be the option if a user wanted to preserve his/her data even after an app Uninstall/Reinstall?
In second case, I am considering manual/automatic backup of SpecialFolder.Personal db version in use and storing it as a separate file outside of the package using External_STORAGE permissions.
Then the user will be able to Import data from external db file copy into the one that comes in the package.
Also, how should the Import look like?
Can I simply replace the file with external one?
Any advice on this topic will be very appreciated.
An update from Google Play will not overwrite the db file
If a user uninstalls the application, he will want to delete everything related with the application. So my best solution is to have a synchronize method within your API so that, when the user installs again the application, it will fill the local DB with the requested data.

How Exactly Updating Play Apps Occur

The Question is how exactly google play updates apps.
I mean does it remove older app exactly from files or it just append on it .
For example in my app i have a local database ,after update, will my older local database become removed?
Your old application is definitely deleted. Your app is compiled and packaged, it won't be opened by Google.
As far your database, if you made changes to your database you need to change the "database version" before publishing. And put code inside the onUpgrade() method of your SQL database. This is how you can successfully change your database. If you want to delete the old database, you can delete it inside the method. The database is on the user's device, and will stay there forever until they delete your app or your code deletes it.
I hope I'm understanding your question.

Data save for an android app after it uninstall or force data clear from settings

I want to give the user some point when they first install the app (but I want it to device specific). It means if he uninstalls and re-installs he will not get that point again. I have found below methods:
Keep device previous data in shared preferences which will be deleted if I release an updates of the app
Store previous data in sql database but if user clears data from settings it will be lost
Create a file in SDcard store data, saving that file in a folder with .foldername and check the file value, problem is that the user can delete it
Every time the user opens the app it sends device id to server, server will check it is previously stored or not before giving point. Problem is that server maintenance should be avoided.
Other than these 3 methods is there any other method?
Can you suggest me any other way,
or can you please tell me if there is no other method which would be better for 3 and 4?
Variation of 4.
using Google's backup servers, however the user can delete the data through his system settings.

How to run code only when my app is updated [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to know my Android application has been upgraded in order to reset an alarm?
I need to run a certain code when my android app is only updated (I specifically want to reschedule alarms).
The did an extensive search on SO and I found that people suggest using SharedPreferences. I dont think this would be correct as sharedPreferences can be deleted upon restart or by simply clearing the cache. Which means when my app is updated, shared preferences may not exist and I may not know if it is an update or simply fresh install ( or even worse a restart).
So, Is there any other way? Perhaps some sort of intent or some sort of method that executes (kinda like onUpgrade for sqlite).
Please advise . Thank you so much
SharedPreferences is the best approach. It is cleared if a user un-installs and installs again, in addition to what you described. If this is not good enough for you, you will need to save the last installed version on a server, but that means you can not run your test when offline.
onUpgrade for sqlite simply check if database is present, then what is its version. If Version of current DB is lower then the one in APK it will clear the DB and updated the DB with new one.
Similarly if you clear the application cache. All the file including the DB will be cleared
Similarly you can implement in you application:
like have a static public int version = 1000; in your app. On application on create check if SharedPreferences contains version ( even if SP is not present ) it will return saved or default method.
If value of SP version if less then the current version in your code. Use the updated function which you intent to use.
And if user uninstalls and reinstalled the app then too you might want to register your calls again.

Saving preference that can be read and modified by another Application

I built an application that will download and install an APK from a WebService using the technique described here:
Install Application programmatically on Android
During this installation, the Webservice sends a 'flag' that indicates if the SQLite database from the application that is being updated should be deleted or not during it´s first run.
Is there any way to set a "Global Preference" that could be read (if the flag is true, the database should be deleted) and cleared (it should be set to false after deletion to avoid deleting the database all times that app is started) during the first usage of the updated app, without saving it to the SDCard?
I know how to read the preferences from the app that is being updated but, I did´t realize how to modify these preferences from another app.
Thanks a lot.
SharedPreferences are unique to each App/APK - no way to share them that I'm aware of and no 'Global' equivalent.
If you want to share data, the solution is usually some sort of ContentProvider, but that relies on both apps running at the same time.
If you only want to hand-over a token or state, I'd suggest writing a file onto the SDCARD is probably the simplest option?
Here is a tutorial on how to do it.
Basically you have to use MODE_WORLD_WRITEABLE for the prefs file.
To get the context for the other package you use createPackageContext()

Categories

Resources