am too much confused in starting a background service from an activity and am providing the code which i used to start the service from an activity.
private boolean isMyServiceRunning() {
ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
Log.v("Running activities", manager.toString());
for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
if ("com.*.*.service.Service".equals(service.service.getClassName())) {
return true;
}
}
Log.v("Currently running services in andorid phone", "other services");
return false;
}
Above code is to check whether the service is running or not.If it is not means am doing this
if(isMyServiceRunning()) {
System.out.println("Service is running");
} else {
System.out.println("Service is not running");
Intent serviceIntent = new Intent();
serviceIntent.setAction("com.*.*.service.Service");
startService(serviceIntent);
}
Suggest your answers and solutions to solve this problem.