Perform a task on uninstall in android [duplicate]

I have developed an Android app. Now I want to perform a few operations (i. e. - Reset the settings etc.. ) at the moment the app gets uninstalled from the phone.

Is it possible to reigster a listener or a function that is called at the moment the app is removed?


Solution 1:

Sadly android at the moment does not give you a possibility to perform code at the moment your app is uninstalled.

All the settings that are set via the SharedPreferences are deleted together with everything in the Application Data an Cache folder.

The only thing that will persist is the data that is written to the SD-Card and any changes to phone settings that are made. I don't know what happens to data that is synchronized to the contacts through your app.

Solution 2:

You cannot get control when your application is uninstalled -- sorry!

Solution 3:

Since API level 8 you may use Context.getExternalFilesDir(). In theory any data placed here will be removed when the application is uninstalled.

http://developer.android.com/reference/android/content/Context.html#getExternalFilesDir(java.lang.String)