![](/img/trans.png)
[英]How to read/write nested ArrayLists when using Parcelable in Android?
[英]How to store nested Arraylists in a Bundle in Android
我的Android App源代碼中有此對象:
ArrayList<ArrayList<MyObject>> rsp
我想將其存儲在Bundle中並在我的活動中的OnSaveInstanceState()
方法中使用它。 然后,我也想從捆綁包中檢索它。
我應該使用json嗎? 還有另一種方法嗎?
如果可能,請使用Gson
庫
Gson gson = new Gson();
String output = gson.toJson(rsp); // Create String and pass through bundle
從字符串中檢索該列表
//convert from string
String output = // get that string from bundle
ArrayList<ArrayList<MyObject>> fromString = gson.fromJson(output,new TypeToken<List<ArrayList<ArrayList<MyObject>>>>(){}.getType());
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.