2012-07-03 68 views

回答

0

所以,您的問題是一樣的,如何知道一個服務是運行與否,對;)

Android有Activity Manager做你的工作。

public boolean checkService(String service) { 
     ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE); 
     for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) { 
      if (service.equals(service.service.getClassName())) { 
       return true; 
      } 
     } 
     return false; 
    } 

釷弦業務,應該是你的類名,例如:com.app.Intent

這是一個僞代碼。我沒有詳細說明,因爲許多方式來啓動您的服務,取決於您如何使用它。

if checkService("com.app.ServiceA") 
    running ServiceA; 
running ServiceB; // Because I see that ServiceB always still always run, not depend on ServiceA 

希望這有助於你:)

+0

這是非常helpful.Thanks很多:) – sunchy

相關問題