1

there are lots of question about this topic but all are only about getting the package name. what i want is get the activity name.

currently i am using the below method to get the activity name but as you know ActivityManager.getRunningTasks is now deprecated, so is there an alternative way to get this or i should stick with this and it won't do any harm?

ActivityManager am = (ActivityManager) context.getSystemService(context.ACTIVITY_SERVICE);
                    List<ActivityManager.RunningTaskInfo> taskInfo = am.getRunningTasks(1);   //deprecated 


//taskInfo.get(0).topActivity.getClassName() //this gets the activity name 
Rashad.Z
  • 2,494
  • 2
  • 27
  • 58
  • Did you tried http://stackoverflow.com/questions/24625936/getrunningtasks-doesnt-work-in-android-l – Pankaj Kumar Mar 16 '15 at 08:58
  • yes i did try that method and was able to get the package name, but was not able to get the current foreground activity name – Rashad.Z Mar 16 '15 at 09:48
  • You can refer [How to get running application activity Name in android 5.0(L)?](http://stackoverflow.com/questions/27689276/how-to-get-running-application-activity-name-in-android-5-0l) – corochann Sep 18 '15 at 06:45

1 Answers1

0

Is Late, but maybe this can help someone else:

String activityName = (String) activity.getTitle();
xyz
  • 524
  • 10
  • 22