2013-03-13 59 views
2

我想通過putExtra從活動更新值到服務,但值始終是舊值。使用putExtra更新bindservice中的值

活動:

ArrayList<String> listTODO = LoadSelections(); 
    Intent i = new Intent(); 
    i.putStringArrayListExtra("liste", listTODO); 
    i.setClassName("de.home.ku1fg", "de.home.ku1fg.RemoteService"); 
    bindService(i, mConnection, BIND_AUTO_CREATE);   

Remoteservice:

public IBinder onBind(Intent intent) { 
    listTODO = intent.getStringArrayListExtra("liste"); 
    return myRemoteServiceStub; 
} 

現在,當我 「清單當然」 活動中的更新,就根據服務沒有變化。 有什麼想法?

回答

0

意圖不會那樣工作。它不會傳遞對象中的引用,它會序列化對象並將其放置在意圖中。因此更新一個版本不會更新其他版本。這就是爲什麼你可以將意圖傳遞給完全不同的活動 - 值沒有被引用,你正在複製。