How move the app to the foreground when in the background on Android O?

302 Views Asked by At

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);
                        }
                    }
                }
0

There are 0 best solutions below