This article describes the method of getting the currently running Activity name of Android, which can avoid notifications in real-time chat. Share it for your reference. The specific methods are as follows:
Recently, when doing IM, you need to know which Activity is currently. Organize two methods yourself
The first one: be more convenient (not available in Service)
Copy the codeThe code is as follows:
private String getRunningActivityName() {
String contextString = ();
return ((".") + 1, ("@"));
}
String contextString = ();
return ((".") + 1, ("@"));
}
The second type: It is a little more troublesome and requires a permission (recommended)
Copy the codeThe code is as follows:
<uses-permission android:name=".GET_TASKS" />
private String getRunningActivityName(){
ActivityManager activityManager=(ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
String runningActivity=(1).get(0).();
return runningActivity;
}
I hope this article will be helpful to everyone's Android programming design.