How do you save/store objects in SharedPreferences on Android?

后端 未结 20 2717
野趣味
野趣味 2020-11-22 13:35

I need to get user objects in many places, which contain many fields. After login, I want to save/store these user objects. How can we implement this kind of scenario?

<
20条回答
  •  北恋
    北恋 (楼主)
    2020-11-22 14:20

    Store data in SharedPreference

    SharedPreferences mprefs = getSharedPreferences(AppConstant.PREFS_NAME, MODE_PRIVATE)
    mprefs.edit().putString(AppConstant.USER_ID, resUserID).apply();
    

提交回复
热议问题