要获取到当前正在运行的activity需要用到ActivityManager。例如:
ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); RunningTaskInfo info = manager.getRunningTasks(1).get(0); String shortClassName = info.topActivity.getShortClassName(); //类名 String className = info.topActivity.getClassName(); //完整类名 String packageName = info.topActivity.getPackageName(); //包名