Skip to content

Instantly share code, notes, and snippets.

@abhimuktheeswarar
Forked from chuangx/TaskManager.java
Created November 22, 2021 09:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abhimuktheeswarar/91065c48e11178de9d9d5b374e6f9987 to your computer and use it in GitHub Desktop.
Save abhimuktheeswarar/91065c48e11178de9d9d5b374e6f9987 to your computer and use it in GitHub Desktop.
Bring your launcher task to front
public class TaskManager {
/**
* Bring up launcher task to front
*/
public void navToLauncherTask(@Nonnull Context appContext) {
ActivityManager activityManager = (ActivityManager) appContext.getSystemService(Context.ACTIVITY_SERVICE);
// iterate app tasks available and navigate to launcher task (browse task)
final List<ActivityManager.AppTask> appTasks = activityManager.getAppTasks();
for (ActivityManager.AppTask task : appTasks) {
final Intent baseIntent = task.getTaskInfo().baseIntent;
final Set<String> categories = baseIntent.getCategories();
if (categories != null && categories.contains(Intent.CATEGORY_LAUNCHER)) {
task.moveToFront();
return;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment