2012-02-07 54 views
1

我有兩個獨立的應用程序使用共同的後臺服務(這是在一個共同的庫中,這兩個應用程序都包含)來收集藍牙數據。在首次安裝應用程序時一切正常。由於兩個應用程序共享庫中的Android服務不被更新

問題是,當其中一個應用程序在通用服務發生變化後重新部署時,它仍然使用先前安裝的服務。

以下是一些信息和示例以澄清事情: 這2個應用程序被命名爲BioSound和BioZen。它們中的每一個都包含一個名爲AndroidSpineServerLib的公共庫,其中包含公共庫AndroidBTService(其中包含後臺服務)

例如,首次安裝時,AndroidBTService的版本號爲1.0。當應用程序部署一切都很好時,BioZen和BioSound都使用V1.0服務。

然後我改變了BioSound和AndroidBTService,將它的版本增加到了V1.1。當我在此之後部署BioSound時,我預計它會使用新更改的服務V1.1,但它仍會繼續使用V1.0服務。解決這個問題的唯一方法是刪除BioZen,然後BioSound提供正確的服務(我甚至不需要重新安裝BioSound)。

以編程方式,當我啓動每個應用程序時,我綁定到該服務,並且當每個應用程序退出時,我解除綁定該服務。

顯然我錯過了一些東西,但無法弄清楚。有任何想法嗎?

回答

0

您的問題可能是您正在使用隱式意圖與您的服務進行通信,該服務並未指定應用程序,而只是一個操作。這個意圖(你在這兩個應用程序中使用)最終會解決一個特定的應用程序的服務。相反,請確保指定與特定組件或類的顯式意圖。有關詳細信息,請參閱Intent docs

0

我確定這是它,但我有困難的細節。

這裏的現有代碼:

Mainfest for the main Application: 
<application android:icon="@drawable/biosound_icon" android:label="@string/app_name" android:debuggable="true"> 
    <service  
     android:name="com.t2.biofeedback.BioFeedbackService"> 
     <intent-filter> 
      <action android:name="com.t2.biofeedback.IBioFeedbackService"/>   
     </intent-filter>  
    </service> 
</application> 

綁定服務的電話是在圖書館AndroidSpineServerLib

Intent intent2 = new Intent("com.t2.biofeedback.IBioFeedbackService"); 
bindService(intent2, mConnection, Context.BIND_AUTO_CREATE); 

所以我可以看到服務是如何綁定到特定的應用程序

爲了解決這個問題,我嘗試過:

Intent intent2 = new Intent(this, BioFeedbackService.class); 
bindService(intent2, mConnection, Context.BIND_AUTO_CREATE); 

問題是該服務未創建。

我也試過以下

In the manifest of the service: 

    <service  
     android:class=".service.BioFeedbackService"> 
     <intent-filter> 
      <action android:name="com.t2.biofeedback.IBioFeedbackService"/>   
     </intent-filter>  
    </service> 

And in the library where I bind the service:  

    Intent intent2 = new Intent(); 
    intent2.setAction("com.t2.biofeedback.IBioFeedbackService"); 
    bindService(intent2, mConnection, Context.BIND_AUTO_CREATE);  

仍然沒有運氣。

也許我把服務定義放在錯誤的清單中。 請記住,我有以下層次結構

Main Application references: 
    AndroidBTService (Library), which references 
    AndroidSpineServerLib (Library) 


So I have 3 manifests and not sure which to update. 
相關問題