How to check whether your service is running in android?
This example will test whether a service is running in android if you know it’s package name.
Run this sample of code to check this.
Run this sample of code to check this.
1
2
3
4
5
6
7
8
9
| private boolean checkMyServiceRunningOrNot() { ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE); for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) { if ( "com.example.your_Service" .equals(service.service.getClassName())) { return true ; } } return false ; } |
No comments:
Post a Comment