开发者

Android- create a service flag

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜