I am using the following code to get the current running activity name in android.
ActivityManager am = (ActivityManager) aContext
.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningTaskInfo> alltasks = am
.getRunningTasks(1);
ComponentName componentInfo = alltasks.get(0).topActivity;
componentInfo.getClassName();
System.out.println("Current:"+componentInfo.getClassName());
This is working fine in all the versions below android 5.0
. But in Android 5.0 it always returning the launcher activity.
Please any one help in this because I want to make run the application in all android versions.