問題:
I have an ArrayList
with custom objects.我有一個帶有自定義對象的ArrayList
。 Each custom object contains a variety of strings and numbers.每個自定義對象均包含各種字符串和數字。 I need the array to stick around even if the user leaves the activity and then wants to come back at a later time, however I don't need the array available after the application has been closed completely.即使用戶離開活動然後想要稍後再回來,我也需要陣列保持住狀態,但是在應用程序完全關閉之後,我不需要陣列可用。 I save a lot of other objects this way by using the SharedPreferences
but I can't figure out how to save my entire array this way.我通過使用SharedPreferences
以這種方式保存了許多其他對象,但是我不知道如何以這種方式保存我的整個數組。 Is this possible?這可能嗎? Maybe SharedPreferences
isn't the way to go about this?也許不是SharedPreferences
可以解決這個問題? Is there a simpler method?有沒有更簡單的方法?
解決方案:
參考一: https://stackoom.com/question/Tc4D參考二: Save ArrayList to SharedPreferences