Android parameters stored in the shared

This method is used in saving data we log in, the server returns the token and other fields, can be saved by sharing parameters

  • Share acquisition parameters
    SharedPreferences sps = getSharedPreferences("share", Context.MODE_PRIVATE);

     

  • Storing data
    SharedPreferences.Editor editor = sps.edit();
    editor.putString("name","Mr Lee");
    editor.putInt("age",30);
    editor.putBoolean("married",true);
    editor.putFloat("weight",100f);
    editor.commit();

     

  • Read data
    String name = sps.getString("name","");
    int age = sps.getInt("age",0);
    boolean married = sps.getBoolean("married",false);
    float weight = sps.getFloat("weight",0);

     

Guess you like

Origin blog.csdn.net/weixin_38322371/article/details/88394451