Android 获取当前活动activity的信息

PackageManager mPackageManager = getApplication().getPackageManager();
ActivityManager mActivityManager = (ActivityManager) getApplicationContext()
                .getSystemService(Context.ACTIVITY_SERVICE);

//get current active activity for user
List<RunningTaskInfo> runningTaskInfos = mActivityManager.getRunningTasks(1);
        RunningTaskInfo taskInfo = runningTaskInfos.get(0);
        ComponentName cn = taskInfo.topActivity;

try {
     ActivityInfo activityInfo = mPackageManger.getActivityInfo(cn, 0);
     //here: something other activity attributes you want
     if((activityInfo.flags & ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS) != 0) {
         return 0;
     }
} catch (NameNotFoundException e) {
            e.printStackTrace();
}