2013-03-13 55 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

意图不会那样工作。它不会传递对象中的引用,它会序列化对象并将其放置在意图中。因此更新一个版本不会更新其他版本。这就是为什么你可以将意图传递给完全不同的活动 - 值没有被引用,你正在复制。