2016-12-28 25 views
0

有這個對象在我的Android應用程序的源代碼:我如何嵌套的ArrayList存儲在一個包中的Android

ArrayList<ArrayList<MyObject>> rsp 

,我想將其存儲在一個包,並在我的活動使用它OnSaveInstanceState()方法。然後我想從捆綁中找回它。

我應該使用json嗎?有另一種方法嗎?

+0

在包中使用'putParcelableArrayList()',MyObject應該實現Parcelable。 –

+0

它適用於嵌套arraylist? –

+1

是的,它應該適用於嵌套列表。 –

回答

0

如果可能的話使用Gson圖書館

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

Retrive從字符串

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