Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android-Close Other Apps

Tags:

java

android

I have some code that will launch a different application using intents but what can I do to close or kill the other app?

Here is the launch code (works great):

Intent i = new Intent();
  i.setAction(Intent.ACTION_MAIN);
  i.addCategory(Intent.CATEGORY_LAUNCHER);
  i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  i.setComponent(
     new ComponentName(resolveInfo.activityInfo.applicationInfo.packageName, 
       resolveInfo.activityInfo.name));

I tried to kill the background processes but no luck:

ActivityManager activityManager = (ActivityManager) context.getSystemService(context.ACTIVITY_SERVICE);
  activityManager.killBackgroundProcesses("com.pandora.android");

I also tried this to kill it:

context.stopService(new Intent(context, Class.forName("com.bla.bla")));

Update:

I want to kill other applications because I launch other applications and users have requested this additional feature (auto kill is a natural extension of auto launch). Please answer the question of how to accomplish this in code. I know about Advanced Task Mgr so it is possible but how?

like image 284
Luke Avatar asked Dec 21 '10 19:12

Luke


2 Answers

I ended up finding the real answer to this question. Please see Automate closing of applications in Android for the solution!

like image 132
Luke Avatar answered Sep 22 '22 18:09

Luke


but what can I do to close or kill the other app?

You don't. Your user can exit that "other app" when they wish to.

like image 30
CommonsWare Avatar answered Sep 23 '22 18:09

CommonsWare