views:

36

answers:

1

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.

A: 

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.

Will Vanderhoef
Additionally, it sounds like he's rotating the phone/screen. When the screen rotates, the current Activity is destroyed and recreated. So your onCreate() method gets called again. I think he's going to have to show us some code.
Andrew