Question

I like to know what of following ideas makes more sentence:

I have three Arrays with more than 5'000 entries. And when I try to put them into Extra, I became the FAILED BINDER TRANSACTION:

  1. Split those big arrays into smaller and give them to the next activity by putExtra

  2. Save those entries to a database and work with sqllite and cursor?

Thanks in advance!

Was it helpful?

Solution

I would choose the second case. Imagine that for some reasons, you have to create more than 3 arrays, would you really split them into smaller, modify the code where you pass them to the next activity ? Imagine now that you have to access to this entries for another activity, you will have to re-implement this stuff. This isn't maintanable.

I don't think this is really judicious to use extras for such stuff. By creating a database you will be able to :

1 - Stock important datas
2 - Access them everywhere

So I would create entries in a database.

OTHER TIPS

I would go with the third option, which partially uses both.

  1. Persist data (e.g. in DB) if you feel like the data is useful to your app. When downloading it from webservice, do this right after parsing and before giving it to the UI thread.
  2. Make a memory cache for the list which can be accessed from both Activities. Some suggest singleton and this might be ok for just holding the list, but I prefer model classes either in Application or @Injected.
  3. If there are many such lists and sometimes you want to send different ones, send a key between Activities.
  4. When retrieving data from the model (or singleton) in second Activity make sure you don't get null after the process is killed and recreate list from DB. I suggest no DB operations on UI thread and making user know data is being recreated and will appear in a couple of milliseconds.

This way you avoid overhead of always getting data from DB, your UI is responsive and doesn't do too much of parceling either.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top