private boolean getServiceTaskName() {
boolean checked = false;
ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningServiceInfo> info;
info = am.getRunningServices(30);
for(Iterator iterator = info.iterator(); iterator.hasNext();) {
RunningServiceInfo runningTaskInfo = (RunningServiceInfo) iterator.next();
Log.i(TAG, "Service name :runningTaskInfo.service.getClassName());
if (runningTaskInfo.service.getClassName().equals("내 패키지명")) {
checked = true;
Log.i(TAG2, "Service is.... : " + checked);
}
}
return checked;
}

하지만 디바이스내 실행되는 서비스 목록이 많다면... 다소 시간이 걸릴수도 있겠으며...
토나올수도 있을것이다.
두번째 방법은 아래코드 처럼 더더욱 간단히 구현 가능하다.
static 형태로 저장한다면, 서비스를 중지 시킬때도 꽤 유익하게 사용할 수 있을것이다.
ComponentName serviceName = startService(serviceIntent);
Intent i = new Intent();
i.setComponent(serviceName);
stopService(i);
또 한가지, 모든 Service를 한 Activity 내에서 종료하지는 않을 것이다...대게는??
Service 를 구현하고 있는 class 내에 stopSelf(); 함수로 종료시켜주자.


0