2

I would like to update values through putExtra from an activity to a service, but the values are always the old one.

Activity:

    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;
 }

Now, when I update the "liste" in the activity, there will no change in the service. Any idea?

4

1 回答 1

0

The intent doesn't work that way. It doesn't pass a reference to the object in the intent, it serializes the object and places it in the intent. So updating one version will not update the other. That's why you can pass an intent to a completely different activity- the values are not being referenced, you're making a copy.

于 2013-03-13T19:14:52.377 回答