简体   繁体   中英

How to handle SharedPreferences in MVP pattern?

How should I handle SharedPreferences in Fragments/Activity? I think it is not good idea to handle it in Fragment just in onPause method?

Treat SharedPreferences exactly like you would treat a Database. It's just a way to save data, so it should be associated with Presenter, and not the View (Fragment/Activity/Custom View)

For example, you can create a wrapper class, like PreferenceAccessor or PreferenceDao, and pass it in the Presenters constructor.

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