I would like to stop an app programmatically. I read that should be done calling to moveTaskToBack()
but I can't figure how can I call it based on a package name like "com.adobe.reader" . I can find his persistent task id searching in the task stack but I don't know what to do now.
public static void stopPackageProcess(String packageName, Context context) {
Context mContext = context;
final ActivityManager am = (ActivityManager) mContext
.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RecentTaskInfo> mTasks =
am.getRecentTasks(Integer.MAX_VALUE, ActivityManager.RECENT_IGNORE_UNAVAILABLE);
for (int i = 0; i < mTasks.size(); i++)
{
String name = mTasks.get(i).baseIntent
.getComponent().getPackageName();
if(name.equals(packageName)) {
// TODO: Stop App
break;
}
}
}