How can a Service check if one of it\'s application\'s Activity is running in foreground?
Use the below method to get full class name (package+class name) of the current activity and check if it is equal to full class name (package+class name) of activity you want:
public String getCurrentClass() {
ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
List runningTaskInfo = manager.getRunningTasks(1);
ComponentName componentInfo = runningTaskInfo.get(0).topActivity;
String className = componentInfo.getClassName();
return className;
}