Does anyone know if a specific method is available to be overridden when my application is uninstalled? It would be nice to remove these users from the server side database when this occurs.
-
if you have found the answer, any pointers will be a great help. I am struggling on this for last two days. – Gaurav Agarwal Jun 15 '12 at 16:49
-
No - I didn't find a solution. Your best bet would be the answer I accepted below. – Kevin Parker Jun 15 '12 at 18:54
-
I didn't anything when uninstalled directly from GPlay – Kevin Parker Jun 15 '12 at 20:22
-
Possible duplicate of [How it works: warning that app is going to be uninstalled?](http://stackoverflow.com/questions/18692571/how-it-works-warning-that-app-is-going-to-be-uninstalled) – Dan Dascalescu Jan 21 '16 at 03:10
4 Answers
Unfortunately there is currently no way for an Android package to execute code when it is removed. However, you can register a BroadcastReceiver
for ACTION_PACKAGE_REMOVED
in a different package that will be called when packages are removed from the phone.
Also see this question.

- 1
- 1

- 74,165
- 16
- 97
- 99
-
How to register `ACTION_PACKAGE_REMOVED` in a different package? – Gaurav Agarwal Jun 15 '12 at 16:48
-
@GauravAgarwal get the user to install another app of your from play store or from the assets folder – Dheeraj Bhaskar Nov 27 '14 at 07:08
I know I'm late to the party, but I'm guessing that since for you uninstalling the app is sufficient to blow away the user at the server (as opposed to the user explicitly picking a "delete my account" option), I would create a job on the server/service-side that scans for inactive users every N units of time (eg. 30 days) and deletes them. Why? An app that never connects to your server is as good as an app that is uninstalled.
However, you can then build logic in your app to handle the case when those users that never uninstalled the app, but don't log in for over N units of time, eventually come back. Then, you could:
- make the app send a special "I'm already installed" cookie to the server, which then instructs the app to send it enough app-side cached info to reconstruct the user data at the server while saying "Please wait, syncing with server...". This should work as long as the user data is not huge (for eg. some sort of image library), and if it is, your best bet then is to indicate in BOLD letters that inactive accounts will be deleted.
- Or, of course, you could also just reset the app to its original state and hope the user does not hate you.
You could go the route to install a service as part of your app that wakes up once a day and when WiFi is available and the device is on A/C power, sends a "heartbeat" to your service saying "I'm installed". If the heartbeat stops for more than a few days, you can assume the user uninstalled the app and delete the user data. But note that this is not foolproof, since the user may simply have turned the device off for that many days. In which case, you now have to handle the situation when a heartbeat comes in for a user that is no longer active in the system, at which point you will need to build in reconstruction logic as before (which buys you nothing for having gone through this pain of building the heartbeat, thanks a lot), or, you simply reset the app to its fresh state and hope the user doesn't hate you (which again buys you nothing for having gone through this pain of building the heartbeat, thanks a lot).
Those pesky users! ;-)

- 5,612
- 3
- 42
- 62
Yes, there is a way where you can Use Android listener application to install and uninstall App.
App install and uninstall will send a broadcast when the application installation is complete, the system will listen android.intent.action.PACKAGE_ADDED
broadcast. The name of the package that was installed by intent.getDataString()
. When the uninstall program system listens android.intent.action.PACKAGE_REMOVED
the radio. The same intent.getDataString()
to get the the uninstall package name. The application can not monitor the installation and uninstallation, but cover the installation can listen to their own android.intent.action.PACKAGE_REMOVED
broadcast.
Example
AndroidManifest.xml configuration file:
<receiver android:name="com.sarbjot.MyApp.BootReceiver" >
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.intent.action.PACKAGE_ADDED" />
<action android:name="android.intent.action.PACKAGE_REMOVED" />
<data android:scheme="package"/>
</intent-filter>
</receiver>
And the receiver call:
package com.sarbjot.MyApp;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
public class BootReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// install call
if (intent.getAction().equals("android.intent.action.PACKAGE_ADDED")) {
//code here on install
Log.i("Installed:", intent.getDataString());
}
// uninstall call
if (intent.getAction().equals("android.intent.action.PACKAGE_REMOVED")) {
//code here on uninstall
Log.i("Uninstalled:", intent.getDataString());
}
}
}
I hope it will help you all.

- 6,405
- 16
- 66
- 120

- 2,301
- 24
- 33
-
-
2This only works when other apps get installed/uninstalled. That is, the app which defines this receiver will not be notified. So this isn't what the OP actually asked. – Sufian May 03 '16 at 07:35
Yes, You can handle it by identifying click on Uninstall Button from Settings -> Manage Apps -> Selects a particular application.
try this answer.
Hopefully this will works.

- 1,073
- 1
- 12
- 19