How to save an ArrayList in a bundle object

Hi
I need help finding a storage method

 ArrayList<HashMap<String,String>> 

in the Bunble object so that I can return them back to onRestoreInstanceState (package state) when orientation happens. I can find methods for storing simple arrays in Bunble, but not for ArrayList.

+3
source share
1 answer

you must first have a static holder:

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

second, at the beginning of orientation, you should return the object that you want to receive after orientation:

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

finally, when you create a “new” action, you must call getLastNonConfigurationInstance (). ANdroid will return your holder with your list.

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

: .

+3

Source: https://habr.com/ru/post/1781849/


All Articles