SharedPreferences application context vs activity context

后端 未结 3 1821
清歌不尽
清歌不尽 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:27

    SharedPreferences are managed internally by Android as singletons. You can get as many instances as you want using:

    context.getSharedPreferences(name, mode);
    

    as long as you use the same name, you'll always get the same instance. Therefore there are no concurrency problems.

提交回复
热议问题