Question

I'm having a problem with my ListView in a ListActivity with a Custom ArrayAdapter.

When the ListActivity becomes hidden (paused, whatever), the data that was present in the ArrayAdpater seems to go away. Rotation works fine, but I am only assigning the array in the ArrayAdapter in the onCreate(), nowhere else. The array is stored in a global static so the array itself should be fine. but the ListView seems to be pitching the array somewhere after the onCreate in the Activity Lifecycle.

I'm thinking the array should be re-assigned on one of the onResume(), onStart() or onRestart(), but I'm looking for a more concrete reason as this happens only rarely and never with my Cursor based Adapters.

Was it helpful?

Solution

Your problem is a little vague, but I'll present a few tips to consider.

Don't populate data inside the onCreate method. onCreate() should be used to define the view. Use the onResume() to load data so you can clean up and save memory effectively with the onPause().

Be sure your custom ArrayAdapter is appropriately handling getView as this can be a source of other problems.

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