Perform a Task on Uninstall in Android

Perform a task on uninstall in android

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.

How to Call custom Method at time of uninstallation of application in Android

I'm afraid that you can't control when application is uninstalled. Sorry.

Can code be called when my Android application is uninstalled?

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.

How to show an Activity BEFORE my app is uninstalled (Android)

I noticed that NQ Mobile Security is able to show a message after I click on Uninstall and before the PackageUninstaller is called

They must be exploiting some security flaw in Android. I will research it and see if I can get it fixed. Apps are not supposed to get control at uninstall time.

Thanks for pointing this out!

Is there a different way to intercept your application UNINSTALL event?

I sure hope not.

How do I uninstall and re-run an app on a device using Android Studio?

You can skip the force stop and uninstall step by just hitting run again. Android Studio should prompt you which device to run on and there you can select your connected device.

It will close the app and re-run your changed version.

Run connectedAndroidTest and skip uninstall

Looking at the sorce of gradle plugin there is no way to prevent uninstalling app at the end of test task. You can check that in SimpleTestCallable class of android gradle plugin.

From what i see there are two options to acchive what you want.

First one is to reinstall app after your connected check is done. Command to do that would look something like this. ./gradlew connectedCheck installDebug installDebugAndroidTest This will execute test on device and delete apps from it. But after that it will reinstall app and test app. So app will still be removed and then installed which means a bit of owerhead but at least apps will not be recompiled twice since you are executing in same gradle execution.

Second option is to not use gradle for executing tests but use adb instead.
To do this you first need to install app and test app through gradle.
./gradlew installDebug installDebugAndroidTest

After that you can execute tests through adb. by caling adb shell am instrument -w com.example.test/android.support.test.runner.AndroidJUnitRunner.

When this is done you can run your cli tests since both app and test app are still installed.

With second approach you would lose all the benefits of executing test wit gradle. Such as code coverage and executing in multiple proceses, etc.



Related Topics



Leave a reply



Submit