From http://www.eoeandroid.com/thread-42812-1-1.html
Obtain the currently displayed Activity
Activitymanager can be used to obtain all the tasks, processes, and services currently running. This is the core of the task manager.
Take a closer look at the getrunningtasks document. It indicates that all tasks in the system "running" are obtained. The "running" status includes tasks that have been frozen by the system. In addition, the returned list is arranged in order, that is, the first one must be later than the second one.
Getrunningtasks has an integer parameter, indicating the maximum number of returned lists. Then, if we take 1 as the parameter, the task returned by him will be the task currently running, and the top-level activity will be obtained from the task, this activity is the activity currently displayed to the user.
- Activitymanager AM = (activitymanager) getsystemservice (activity_service );
- Componentname Cn = aM. getrunningtasks (1). Get (0). topactivity;
- Log. D ("", "PKG:" + CN. getpackagename ());
- Log. D ("", "CLS:" + CN. getclassname ());