Android: Whats the easiest way to save small amounts of data?
I have an app that only requires the value of a textview field to be saved... what would be the most simpl开发者_开发问答e and efficient way to save such a small amount of data? Creating a database for this seems like overkill. would onSaveInstanceState be sufficient?
This sounds like a job for SharedPreferences.
You could also consider saving it to cache. Keep in mind if you use internal storage for your cache, it may be deleted if there is low memory. Using Shared preferences also works as Yoni had mentioned and will ensure that the data is not deleted even if on low memory.
SharedPreferences is the easiest if you want it to be persisted across sessions.
I think onSaveInstanceState will not survive a closing of the whole application like it will happen if you shut down the phone or your app crashes.
Go with the sharedPreferences Yoni mentioned. They will make your data persistent on the phone memory without much work for you.
精彩评论