1

I have a very large data set for my base adapter in my Twitter-like app, which consists of custom models (with nested references) which are quite large in themselves.

The issue i'm having is, when re-creating the Activity on orientation change, the list is quite slow to populate (i'm currently passing the data set through onSaveInstanceState)

I've looked into changing the way I serialise the models (currently using Kryo which has sped up the saving to disk aspect), caching to disk and reloading in onCreate, using setRetainInstance(true) in the list fragment, i've also tried handling configuration changes in the parent Activity.

Although the latter is the quickest, it's also the last option I want to take as there's a lot of downsides to handling orientation and would also mean having to re-write chunks of code.

My question is, what is the best practice of handing adapter repopulating on orientation?

I can foresee OOM errors when serialising the list to pass through onSaveInstanceState

Edit: Possible duplicate Best way to persist data between orientation changes in Android

Community
  • 1
  • 1
ScruffyFox
  • 150
  • 2
  • 9
  • http://developer.android.com/guide/topics/resources/runtime-changes.html. check the docs. – Raghunandan Jul 23 '13 at 20:03
  • How do you populate the list to begin with? – Vikram Jul 23 '13 at 20:04
  • From where did You get Your values? Maybe a database i sa solution – Opiatefuchs Jul 23 '13 at 20:06
  • The list is populated from a HTTP request (or loaded from a cached file if exists) – ScruffyFox Jul 23 '13 at 20:07
  • Since you're loading only 30 items into the ListView, one option could be to cache only a subset of your data. `The list is populated from a HTTP request (or loaded from a cached file if exists)`. The rest can be retrieved as and when required. – Vikram Jul 23 '13 at 20:29

2 Answers2

0

You shouldn't be loading all the data into the listview, only the necessary parts. Look into something like this: https://github.com/commonsguy/cwac-endless

Edit: You can also use a library like RoboSpice (https://github.com/octo-online/robospice), to handle the caching of the data for you, this will greatly decrease the lag.

Ryan S
  • 4,549
  • 2
  • 21
  • 33
0

One of the options is to avoid recreating activity on orientation change: For this, in app manifest set configChangesAttribute like this

<activity android:name=".MainActivity"
          android:label="@string/activity_title"
          android:configChanges="keyboardHidden|orientation|screenSize">
antonv
  • 1,227
  • 13
  • 21