In Android service, I wrote a code that moves the app to the foreground when it's in the background. But I knew that "getRunningTasks" were no longer used I'm curious how I should write it.
ActivityManager am = (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningTaskInfo> tasks = am.getRunningTasks(20);
if (!tasks.isEmpty()) {
int taskSize = tasks.size();
for (int i=0;i< taskSize; i ++) {
ActivityManager.RunningTaskInfo taskInfo = tasks.get(i);
if (taskInfo.topActivity.getPackageName().equals(getPackageName())) {
am.moveTaskToFront(taskInfo.id, 0);
}
}
}