Android gets the name of the activity class that is currently being displayed

  • 2020-06-15 10:10:33
  • OfStack

This article example shows how Android gets the name of the activity class that is currently being displayed. Share to everybody for everybody reference. Specific implementation methods are as follows:

First, add one permission:

<uses-permission android:name="android.permission.GET_TASKS"/>

The Java code is as follows:

ActivityManager manager = (ActivityManager)   getSystemService(Context.ACTIVITY_SERVICE);    
List<RunningTaskInfo> runningTasks = manager .getRunningTasks(1);   
RunningTaskInfo cinfo = runningTasks.get(0);   
ComponentName component = cinfo.topActivity;   
Log.e("current activity is ", component.getClassName());

I hope this article has been helpful for your Android programming.


Related articles: