Skip to content

Instantly share code, notes, and snippets.

@easternHong
Created October 6, 2014 02:37
Show Gist options
  • Save easternHong/df35eff2100afcd3eff3 to your computer and use it in GitHub Desktop.
Save easternHong/df35eff2100afcd3eff3 to your computer and use it in GitHub Desktop.
checkService running or not
/**
* 判断服务是否启动
*
* @param className
* @return
*/
private boolean checkServiceRunning(String className) {
boolean isRunning = false;
ActivityManager am = (ActivityManager) this
.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningServiceInfo> amRun = am
.getRunningServices(30);
if (amRun.size() < 1)
return false;
for (int i = 0; i < amRun.size(); i++)
if (amRun.get(i).service.getClassName().equals(className)) {
isRunning = true;
break;
}
return isRunning;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment