开发者

Android- create a service flag

开发者 https://www.devze.com 2023-03-21 16:21 出处:网络
How would I go about creating a flag so that if a service is running, and the user clicks on another listview item that it will check to see if a service is running, and thus stop it? Tha开发者_如何学

How would I go about creating a flag so that if a service is running, and the user clicks on another listview item that it will check to see if a service is running, and thus stop it? Tha开发者_如何学Pythonnks


You could use something like -

private boolean isMyServiceRunning() {
ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
    if ("com.example.MyService".equals(service.service.getClassName())) {
        return true;
    }
}
return false;
}

Ref - How to check if a service is running on Android?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号