In my app I want to bring the background app to foreground by knowing its package name. I know it can be done using moveTaskToFront() method but I don't know how to implement it.I am currently testing it on Lollipop android version.Can anyone know the solution..
Asked
Active
Viewed 2,617 times
1 Answers
1
ActivityManager am = (ActivityManager) getSystemService(Activity.ACTIVITY_SERVICE);
List<RunningTaskInfo> rt = am.getRunningTasks(Integer.MAX_VALUE);
for (int i = 0; i < rt.size(); i++)
{
// bring to front
if (rt.get(i).baseActivity.toShortString().indexOf("yourproject") > -1) {
am.moveTaskToFront(rt.get(i).id, ActivityManager.MOVE_TASK_WITH_HOME);
}
}
Inside your manifest add :
<!--User Permissions-->
<uses-permission android:name="android.permission.GET_TASKS" />
<uses-permission android:name="android.permission.REORDER_TASKS" />
Nir Duan
- 5,746
- 4
- 22
- 38
-
If you are only interested in top activity of **your own app**: you can use `getAppTasks()`. Also look on this answer: http://stackoverflow.com/a/26451064/6028746 – Nir Duan Jul 19 '16 at 08:40
-
No,I want to move the background apps to foreground using its package name – Adarsh Jul 19 '16 at 08:58
-
Starting Android L getRunningTasks() can't give us the task information. – Alexey Ozerov Nov 27 '20 at 02:53