I have an activity containing a ListFragment. It's populated from a restful webservice. When I click on an item in the list I send back the id of that item to my activity. And using an intent pass that on to a second detail activity and request the object by id from the webservice again.
I'm considering if I should send the object, instead of just it's id, to the detail activity? That would save me a http request and make things a little less complicated.
However that would also mean that I'm required to have the entire object and in the futura that might be not be the case... what to do?
Only pass ids, and heres why:
- Passing Objects is slow or complicated when using Parcable
- When passing objects directly you have highly coupled services (activities), which is bad practice, handle activities as if they are in their own process (which actually happens in certain situations, e.g. calling activity from anohter app)
- Your object could be already out of date (e.g. user browses the list for couple of minutes and then opens an item)
The problem that you have an additional http request SHOULD be mitigated by good design of your backend, meaning you should have http cache features implemented (e.g. etags, last-modified cache-control headers,etc). This will give you the advantage that you always have the latest data from your server but only if needed. This should happen transparently so not to complicate your logic (check out Volley e.g.), also if you cannot use the http cache header and behavoiur have a local cache work in front of your http client.