我的 Android App 源代码中有这个对象:
ArrayList<ArrayList<MyObject>> rsp
我想将它存储在一个Bundle中并OnSaveInstanceState()
在我的活动中使用它。然后我也想从包中检索它。
我应该使用json吗?还有其他方法吗?
我的 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
从 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());
您可以在 OnSaveInstanceState() 期间使用 Parcelable 将数据存储在 Bundle 中
使用以下链接了解更多详情: