인 텐트 서비스를 호출하는 업로드 활동이 있습니다. 거기에 API 요청 호출을 처리하고 있습니다.Android : IntentService가 실행 중인지 확인하는 방법
서비스가 실행 중인지 여부를 알기 위해 업로드 태그를 표시하고 싶습니다.
나는 서비스가 실행되고 있는지 확인하려면 다음을 시도 :public void startUploadServiceTask() {
if (Util.isNetworkAvailable(mContext)) {
if (!isMyServiceRunning(UploadDriveService.class)) {
startService(new Intent(mContext,
UploadService.class));
}
} else {
Toast.makeText(mContext,
"Service is already running.", Toast.LENGTH_SHORT)
.show();
}
} else {
Toast.makeText(mContext,
getString(R.string.please_check_internet_connection),
Toast.LENGTH_SHORT).show();
}
}
private boolean isMyServiceRunning(Class<?> serviceClass) {
ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
for (RunningServiceInfo service : manager
.getRunningServices(Integer.MAX_VALUE)) {
Log.e("ALL SERVICE", service.service.getClassName().toString());
if (serviceClass.getName().equals(service.service.getClassName())) {
return true;
}
}
return false;
}
그러나 서비스 정보를 실행 작업 관리자에서
가, 내가 실행하고 의도 서비스의 클래스를 받고 있지 않다, 그래서 이것은 항상 false를 의미합니다.API 호출에 Broadcast를 사용했습니다.
이 코드도 확인했습니다.
if(startService(someIntent) != null) {
Toast.makeText(getBaseContext(), "Service is already running", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getBaseContext(), "There is no service running, starting service..", Toast.LENGTH_SHORT).show();
}
그러나이 코드에서는 서비스를 확인할 때 서비스가 다시 시작되므로 서비스가 두 번 호출됩니다.
도와주세요.
이것을 시도하십시오. http://stackoverflow.com/a/17591175/2798289 – Govind
이것은 확실히 당신이 원하는 것입니다 : http : // stackoverflow.com/questions/7440473/android-how-to-the-intent-service-is-still-run-stopped-run-runni – Vektor88