activitymanager--Gets the top of the stack activity and its owning process, Activitymanager
Gets the stack top activity and its owning process public
static String Gettopactivitynameandprocessname (context context) {
string Processname=null;
String Topactivityname=null;
Activitymanager Activitymanager =
(Activitymanager) (Context.getsystemservice ( Android.content.Context.ACTIVITY_SERVICE));
list<runningtaskinfo> Runningtaskinfos = activitymanager.getrunningtasks (1);
if (Runningtaskinfos! = null) {
componentname f=runningtaskinfos.get (0). topactivity;
String topactivityclassname=f.getclassname ();
String temp[]=topactivityclassname.split ("\ \");
Top of the stack activity name
topactivityname=temp[temp.length-1];
int Index=topactivityclassname.lastindexof (".");
Stack top activity belongs to the process name
processname=topactivityclassname.substring (0, index);
SYSTEM.OUT.PRINTLN ("---->topactivityname=" +topactivityname+ ", processname=" +processname);
}
Return topactivityname+ "," +processname;
}
Note Permissions:
<uses-permission android:name= "Android.permission.GET_TASKS"/>
Android in the periphery, how to get stack top acitivity context
Do not know whether the following methods meet your problem:
When a method in the perimeter class is called in the top activity of the stack, the context of the top activity is passed through.
How to close the specified activity is obtained first through the method below. your way of doing this is to get activity through a task, only to find the corresponding activity[mw_shl_code=java,true]activitymanager am = (Activitymanager) based on the location of the task. ) This.getsystemservice (Context.activity_service); ComponentName cn = Am.getrunningtasks (2). Get (0). topactivity; [/mw_shl_code]