Skip to content

Instantly share code, notes, and snippets.

@chuangx
Last active November 22, 2021 09:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save chuangx/e8ad898db9e70c81263b1f1cd0e14619 to your computer and use it in GitHub Desktop.
Save chuangx/e8ad898db9e70c81263b1f1cd0e14619 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