Here's what i want: My app is having a button for closing another independent application say - Google map. I want to know if the process has started and if it does then i want to close it by pressing that button.
Asked
Active
Viewed 63 times
1
-
What did you find online? What hace you tried? – Mariano Oct 01 '15 at 01:36
-
3Possible duplicate of: http://stackoverflow.com/questions/12036895/kill-another-application-in-android – Knells Oct 01 '15 at 01:37
-
The application that i want to close/kill doesn't have the same user id i,e it's not my application... @Knells – Peeyush karnwal Sep 27 '16 at 07:42
1 Answers
4
You can use the BroadcastReceiver Class. Try this way.
public class MyBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (isAppForground(context)) {
// App is in Foreground
} else {
// App is in Background
}
}
public boolean isAppForground(Context mContext) {
ActivityManager am = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
List<RunningTaskInfo> tasks = am.getRunningTasks(1);
if (!tasks.isEmpty()) {
ComponentName topActivity = tasks.get(0).topActivity;
if (!topActivity.getPackageName().equals(mContext.getPackageName())) {
return false;
}
}
return true;
}

Nikhil Arya
- 99
- 5