3

Hi
I need help in finding a way to store

 ArrayList<HashMap<String,String>> 

in an Bunble object so that i can retrieve them back in onRestoreInstanceState(Bundle state) when an orientation happens .I can find methods to store simple Arrays in an Bunble,but not an ArrayList like this.

ganesh
  • 1,247
  • 6
  • 24
  • 46
  • ganesh, is the answer you got satisfying you? I have the same problem here, I can't understand where that weird `BitmapDrawable` came from. – azizbekian Sep 17 '12 at 18:45

1 Answers1

3

first you must have a static holder:

private static class Holder{
        private List<BitmapDrawable>imageList = new ArrayList<BitmapDrawable>();
    }

second, when orientation start, you must return the object you want to retrieve after the orientation:

@Override
    public Object onRetainNonConfigurationInstance() {
        return holder;
    }

at last, when you create the 'new' activity must call getLastNonConfigurationInstance(). ANdroid will return your holder with your List.

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
                holder = (Holder) getLastNonConfigurationInstance();
}

you can find a more extensive explanation here: Faster Screen Orientation.

cheers

Franco
  • 7,385
  • 3
  • 27
  • 22