0

I have this object in my Android App source code:

ArrayList<ArrayList<MyObject>> rsp

and i want to store it in a Bundle and use it in OnSaveInstanceState() method in my activity. Then i want to retrieve it from the bundle, too.

Should i use json? Is there another way?

3
  • use putParcelableArrayList() in bundle and MyObject should implement Parcelable. Commented Dec 28, 2016 at 10:34
  • Does it work for nested arraylists? Commented Dec 28, 2016 at 10:35
  • 1
    Yes it should work for nested lists. Commented Dec 28, 2016 at 10:35

2 Answers 2

1

you can use Parcelable to store the data in Bundle during OnSaveInstanceState()

use the below link for more details :

How to save custom ArrayList on Android screen rotate?

Sign up to request clarification or add additional context in comments.

Comments

1

If possible use Gson Library

 Gson gson = new Gson();
    String output = gson.toJson(rsp); // Create String and pass through bundle

Retrive that list from String

    //convert from string
String output =  // get that string from bundle
    ArrayList<ArrayList<MyObject>> fromString = gson.fromJson(output,new TypeToken<List<ArrayList<ArrayList<MyObject>>>>(){}.getType());

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.