判断某个Service是否还活着

public static boolean isServiceRunning(Context context,String serviceName){
        //校验服务是否还活着

        ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
        List<RunningServiceInfo> infos =  am.getRunningServices(100);
        for(RunningServiceInfo info : infos){
            String name = info.service.getClassName();
            if(serviceName.equals(name)){
                return true;
            }
        }
        return false;
    }
阅读更多

没有更多推荐了,返回首页