2010年5月5日 星期三

android 查詢執行中之service

ActivityManager am =
(ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);
List runningServices =
am.getRunningServices(1000);

then just loop through that list to see if your service is running i.e

count = runningServices.size();
Component cnMyService = new ComponentName(this, myService.class);
(for int i=0; i < count ; i++) {
if( runningServices.get(i).service.equals(cnMyService) ) {
// Your service is running, do something
}



data from:http://groups.google.com.tw/group/android-developers/browse_thread/thread/9d3a18d966a320cd

沒有留言:

張貼留言