I'll try to answer all three questions one by one.
is there a beter solution for that? (other then lazy-loading)
That depends. The nice part about lazy-loading is, that you don't need to have all data right at the start when you display the component. The problem often is, how to get new data, as it is needed.
So, when loading the new data from the network, it is really a question of how big the chunks of loaded data are. I would not load one new entry after the next one, but load e.g. 20 new ones, when the end of the list has been reached.
Of course this is just a random idea for a number, you'll need to find the perfect point between speed and usability for your case.
So when you are loading chunks of data from your web-service, which are delivered fast enough, it really is a cool concept. But if you're just reading one entry after another (and therefore, the user almost always waits for new data), this is really just annoying.
And how to proper cache the images?
There are multiple possible solutions available, some of those are:
- Using the system-cache, like the browser (seems to be the
finest).
- Implementing your own system which uses device-storage (e.g. the
SD-Card or the internal application storage (the first one is
preferred)).
You might also like the contents of this question (and it's accepted answer), giving you some general advises on memory-management.
can i retain the data of the adapter when the user rotates the device?
Old, deprecated anser:
Yes, you can use the "instance state" of the Activity to do this.
Basically, the onSaveInstanceState()
-method from the Activity
allows you to populate a given Bundle
with state-information, which
is then passed to the onCreate()
-method.
The data you would save in the Bundle
would be (for example) the
current position of the list or maybe even the list itself (depending
on the size).
Yes, use the Loaders API. It is also available in the compatibility library.