LoginSignup
13
10

More than 5 years have passed since last update.

裏でServiceが動いているか確認するコード

Last updated at Posted at 2015-04-30

ネタ元
http://stackoverflow.com/questions/600207/how-to-check-if-a-service-is-running-on-android

毎回ググっていたのでメモ

    private boolean isYourServiceWorking() {
        ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
        for (ActivityManager.RunningServiceInfo serviceInfo : manager.getRunningServices(Integer.MAX_VALUE)) {
            if (YourService.class.getName().equals(serviceInfo.service.getClassName())) {
                return true;
            }
        }
        return false;
    }
13
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
10