Is there an alternative for getRunningTask API

前端 未结 2 1603
小蘑菇
小蘑菇 2020-12-02 16:18

I was using getRunningTask API in one of my application to find the Foreground application. This API has been deprecated since Lollipop. After this deprecation, I preferred

2条回答
  •  情话喂你
    2020-12-02 16:56

    Get the list of RunningAppProcessInfo by ActivityManager.getRunningAppProcesses(). Choose the RuningAppProcessInfo with whose importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND and whose processState == ActivityManager.START_TASK_TO_FRONT. (The former is easy, the latter is difficult because the reflection is necessary)

    See my answer for this question getRunningTasks doesn't work in Android L

提交回复
热议问题