android 获得当前活动的Acticity

ActivityManager activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);

ComponentName componentName = activityManager.getRunningTasks(1).get(0).topActivity;

Log.d("", "package:"+componentName .getPackageName());

Log.d("", "class:"+componentName .getClassName());



添加权限:android.permission.GET_TASKS

你可能感兴趣的:(android)