我想用自定義對象保存一個ArrayList,以便當我移動到另一個片段並回到它時,它不必重新加載數據。到目前爲止,儘管使對象Parcelable並將其保存在onSaveInstanceState方法中,但我還是無法實現此目的。在片段onPause方法保存ArrayList <自定義對象>
0
A
回答
0
您也可以按住此列表中的ApplicationContext的引用和獲取數據這樣 - 所以你不需要序列化/反序列化
0
如果你不想使用parcelable對象,你可以試試這:
1- By using GSON library, create jsonString from your Custom Arraylist.
2- Send this jsonString to Fragment by using Bundle.
3- Recieve jsonString from bundle and parse it to Custom Arraylist by using GSON Library again.
4- You can also save it to SharedPreferences as a String.
注意:這不是一個好方法,但容易爲您選擇。
相關問題
- 1. 把一個ArrayList <String>到一個ArrayList <自定義對象>
- 2. 如何在onPause(Android)中保存更改/更新ArrayList <Objects>?
- 3. 保存ArrayList <地圖<字符串,對象>> android
- 4. Android:在onPause和onResume之間保存用戶定義對象的ArrayList
- 5. Android保存一個ArrayList <CustomObject> onPause和onSaveInstanceState
- 6. 保存和恢復片段中的自定義對象
- 7. ArrayList <自定義對象> saveInstanceState不返回列表
- 8. 綁定的ArrayList <ArrayList<>>在自定義適配器在Android中
- 9. 從ArrayList中<object>刪除一個對象保存在sharedPreferences
- 10. 存儲自定義對象的ArrayList
- 11. 簡單的方法來使ArrayList對象[] [] <Object>與對象的字段
- 12. 保存自定義對象的狀態 - 在onResume方法
- 13. 自定義對象的Arraylist
- 14. 對象自定義類Arraylist
- 15. ArrayList的自定義對象
- 16. 保存自定義對象ArrayList的狀態
- 17. 將自定義對象的ArrayList保存爲用戶設置
- 18. 保存自定義對象在屏幕上旋轉在片段或活動
- 19. Android Array對象在ArrayList中的調用方法<Object>
- 20. 在Android中保存ArrayList <Object>
- 21. 在orientationChange中保存ArrayList <Fragment>
- 22. 在SharedPreferences中保存ArrayList <pojo>
- 23. ArrayList的自定義方法
- 24. ArrayList的<String>方法
- 25. android:在MainActivity的AsyncTask中使用arrayadapter <自定義對象>
- 26. Android - 片段findViewById自定義方法
- 27. 將WPF DataGrid ItemsSource綁定到方法,IEnumerable <TableRow> GetRows(),自定義Table對象?
- 28. ArrayList的用法<ArrayList<E>>
- 29. 如何在arraylist中保存片段android
- 30. 將對象保存到文件。自定義方法添加/刪除對象