Code example for ActivityManager

Methods: getRunningTasks

0
	 
	private static final String TAG = "ActivityUtils";
	 
	public static boolean isTopActivity(Context context,String packageName){
		ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
        List<RunningTaskInfo>  tasksInfo = activityManager.getRunningTasks(1);  
        if(tasksInfo.size() > 0){  
            //应用程序位于堆栈的顶层   
            if(packageName.equals(tasksInfo.get(0).topActivity.getPackageName())){  
                return true;   
            }   
        }   
        return false;   
    }   
	 
	public static int randomColor(){ 
		  return Color.argb(127, ((Long)Math.round(Math.random() * 255)).intValue(), ((Long)Math.round(Math.random() * 255)).intValue(),((Long)Math.round(Math.random() * 255)).intValue() );
	} 
	 
	/** 
Stop searching for code, let great code find you!  Add Codota to your java IDE