Hi I have one activity and one service class from activity am starting service in one point i want to start service but at same point i want to check that service is already running if yes then i dont want to call start service if not then i will strat but my problem is that how i will get to know that service is running or not?
i used below code but it not working for me is any other code which will help me out
private boolean isServiceRunning() {
ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
for (RunningServiceInfo service : manager
.getRunningServices(Integer.MAX_VALUE)) {
if ("TimerService".equals(service.service.getClassName())) {
Toast.makeText(getApplicationContext(), "running", 100).show();
return true;
}
}
Toast.makeText(getApplicationContext(), "not running", 100).show();
return false;
}
this code always show me not tunning even if it is running