How to find the current foreground activity in android

前端 未结 2 569
别跟我提以往
别跟我提以往 2020-12-06 12:11

Is it possible to find the current foreground activity in android.I am not using ActivityGroup.

2条回答
  •  庸人自扰
    2020-12-06 13:00

    try below code : you need to give proper permission

    private String getCurrentTopActivity() {
    
            ActivityManager mActivityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
            List RunningTask = mActivityManager.getRunningTasks(1);
            ActivityManager.RunningTaskInfo ar = RunningTask.get(0);
            return ar.topActivity.getClassName().toString();
        }
    

提交回复
热议问题