is there a way to retain some of my data after uninstalling the app and than again installing it on the device. I need to check if my app had been installed on one's device previously or not.
-
Does this answer your question? [How to store data that remains after uninstall](https://stackoverflow.com/questions/4022975/how-to-store-data-that-remains-after-uninstall) – Josh Correia Aug 26 '20 at 21:56
2 Answers
Yeah it's possible if you save App Data in External Storage of your device because that data is not deleted even if your app is uninstalled.
Upon reinstalling the app, you can read the file data to determine was the app previously installed or it is a fresh install in case that file doesn't exists.
Note:- Data in External Directory would be visible to user so it might be a case that user may delete the data from file manager.

- 2,120
- 1
- 12
- 20
-
create a hidden folder or file. User will not see it unless he opts for show hidden folders option. All you have to do is to add '.' behind folder or file name like ".MyAppFile" – Sandeep Bhandari Mar 03 '16 at 11:02
-
That is what the issue. I don't want to save the file on external device because i dont want to share that data with the user. It is extremely private data and as i told you that it is very important, i also dont let user to delete that file – k_dev Mar 03 '16 at 11:08
-
1So possibly you can send the device id during start of your app. Server would have device id for all the devices on which your application was installed. Checking against that you can download that data from server ans store in Internal Storage of your device. – Mayank Bhatnagar Mar 03 '16 at 11:32
-
i have voted for you but dont have enough reputation points so my vote is not showing publicly :( – k_dev Mar 03 '16 at 11:47
You can use shared preferences to store this data. Create the sharedreferences with MODE_WORLD_READABLE. You can set a flag as true when the app is run, and can extract this value on each installation to find out whether this value exists. Something like below:
When the app is run(Write this code in the launch code for your app-which is triggered first):
SharedPreferences sharedpreferences = context.getSharedPreferences("test", Context.MODE_WORLD_READABLE);
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString("app_already_installed", "true");
editor.commit();
Checking whether the app was already installed(Write this where you want to check for earlier installations):
SharedPreferences sharedpreferences = context.getSharedPreferences("test", Context.MODE_WORLD_READABLE);
String is_app_already_installed= sharedpreferences.getString("app_already_installed", "false");
if(is_app_already_installed.equals("true"){
//do-something
}
else{
//do-something
}

- 1,224
- 3
- 23
- 48