当前位置:操作系统 > 安卓/Android >>

获取某service是否在运行

 

/**

     * 判断sevice是否运行着

     * 

     * @param serviceName

     * @return

     */ 

    public boolean isServiceRunning(String serviceName) { 

        ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); 

        List<RunningServiceInfo> infos = manager.getRunningServices(30); 

        for (RunningServiceInfo info : infos) { 

            if (info.service.getClassName().equals(serviceName)) { 

                return true; 

            } 

        } 

        return false; 

    }   

 

tao_zi7890的专栏

补充:移动开发 , Android ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,