android判断服务是否是运行状态

/** 
     * 判断服务是否处于运行状态. 
     * @param servicename 
     * @param context 
     * @return 
     */ 
    public static boolean isServiceRunning(String servicename,Context context){  
        ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);  
        List<RunningServiceInfo>  infos = am.getRunningServices(100);  
        for(RunningServiceInfo info: infos){  
            if(servicename.equals(info.service.getClassName())){  
                return true;  
            }  
        }  
        return false;  
    }

 

posted @ 2016-05-30 16:56  魔流剑  阅读(2562)  评论(0编辑  收藏  举报