Difference between getDefaultSharedPreferences and getSharedPreferences

前端 未结 6 656
臣服心动
臣服心动 2020-11-22 13:13

What is the difference between getDefaultSharedPreferences and getSharedPreferences in Android? Can anyone please explain?

6条回答
  •  说谎
    说谎 (楼主)
    2020-11-22 13:21

    Both getSharedPreferences() and getDefaultSharedPreferences() are used to access application-level preferences .getDefaultSharedPreferences() is used to get the shared preferences that work in accordance with Android’s overall preference framework. getDefaultSharedPreferences() is better to use as it gives the SharedPreferences object that works with a PreferenceActivity by default.

提交回复
热议问题