简体   繁体   中英

Android onSaveInstanceState for all instances of activity

After reading the documention it seems that onSaveInstanceStaate works per instance (as the name suggests). I am just wondering what the preffered method of storing data is so that it is available for all instances of that activity?

As MaciejGorski mentioned in his comment, there are different levels of data storage available in Android :

  1. Shared preferences
  2. Internal storage
  3. External storage
  4. SQLite database
  5. Network

From personal experience, the lower you go down this list, the more complicated your implementation will become. Thus, if you are simply trying to save simple data for your app to be shared among different instances of an activity (or of multiple activities), shared preferences are certainly the way to go. You can even create private shared preferences , which only your app can access.

In any case, check out this SO answer for how to implement them: How to use SharedPreferences in Android to store, fetch and edit values

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM