tags:

views:

106

answers:

3

Hello all,

I have been developing an app, and I need to close another app in my code. Does anyone know any api to call to close an app?

BTW: my app will be pre-installed.

thanks

A: 

If both applications are yours, you can use AIDL for inter-process communication to send a message telling the other application to close. See http://developer.android.com/guide/developing/tools/aidl.html.

poe
+1  A: 

Since 2.2 (i.e. going forward), you can only close the "background processes" of other apps, you are no longer able to close their main activities.

If your app is targeting Android <2.2, look at android.permission.RESTART_PACKAGE

If you want it to work properly on 2.2 and above (which you should :-)), look at android.permission.KILL_BACKGROUND_PROCESSES, but again, this only closes background services and such and might "mess up" the other app rather than doing any good.

With the right permissions, you can then do the following:
private ActivityManager am = (ActivityManager) this.getSystemService(ACTIVITY_SERVICE); am.restartPackage("com.jimmy.appToBeClosed");

Nick
am.restartPackage() has been deprecated, now they use another api "killBackgroundProcesses()". But thanks, really appreciate it.
Jimmy
A: 

You don't ever really want to close another application, due to Android activity lifecycle.
There's no benefit, and always detriment to closing another app if it's not yours, and very little benefit to closing your own.

http://developer.android.com/reference/android/app/Activity.html#ActivityLifecycle

If you know for certain that you'll never, ever need a root activity and its children (an "app"), you can stop it to free memory (it doesn't free that much), but if you do the user may restart it while it's still in cache, stopped, which can cause problems if the stopped state is restored. So this is a bad practice.

Android Dev Dude
Also, pre-installed is the worst idea possible. Please tell your bosses that forcing software on a user is evil. Do you by chance work for Verizon?
Android Dev Dude