How would I go about creating a flag so that if a service
is running, and the user clicks on another listview
item that it will check to see if a service
is running, and thus stop it? Thanks
Asked
Active
Viewed 320 times
1 Answers
0
You could use something like -
private boolean isMyServiceRunning() {
ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
if ("com.example.MyService".equals(service.service.getClassName())) {
return true;
}
}
return false;
}
-
Thanks Suchi. I will try this out right now and let you know my results. Thanks for your help – Splitusa Jul 18 '11 at 15:39
-
So in the "com.example.MyService" I put in my package name with the name of the service at the end right? – Splitusa Jul 18 '11 at 17:06