SharedPreferences application context vs activity context

后端 未结 3 1820
清歌不尽
清歌不尽 2020-12-08 12:56

I am using several SharedPreferences to store data in my app. Some preferences are used in a lot of activites.

I know that the SharedPreferences are internally back

3条回答
  •  春和景丽
    2020-12-08 13:26

    I will prefer using a singleton class for preference, initialize preference once by application context. create getter and setter(get/put) methods to add, update and delete data.

    This way it will create instance once and can be more readable,reusable.

提交回复
热议问题