Code example for ActivityManager

Methods: getRunningTasks

0
	} 
	 
	public boolean isInForeground() 
	{ 
	    ActivityManager activityManager = (ActivityManager) getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE);
	    List<RunningTaskInfo> services = activityManager
	    		.getRunningTasks(Integer.MAX_VALUE);
 
	    if (services.get(0).topActivity.getPackageName().toString().equalsIgnoreCase(getApplicationContext().getPackageName().toString()))
	        return true; 
		 
		return false; 
	}	 
 
  @Override 
  public void onError(Context context, String errorId) {
    Log.e(TAG, "onError - errorId: " + errorId);
  } 
 
}