判断Service是否在运行

private boolean isServiceRunning() {
ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
if ("com.baidu.location.service.MyLocationService".equals(service.service.getClassName())) {
return true;
}
}
return false;
}
@Override
    protected void onStart() {
// TODO Auto-generated method stub
super.onStart();
if(this.isServiceRunning()){
startLocation.setText(getString(R.string.stoplocation));
}else{
startLocation.setText(getString(R.string.startlocation));
}

}
posted @ 2016-07-19 14:28  Wei_java  阅读(1562)  评论(0编辑  收藏  举报