背景                                                                                            

SharedPreferences我觉得是最容易上手的,以xml方式存储。

代码                                                                                            

public class share {
    public static void saveInfo(Context context,String username,String password)
    {
        SharedPreferences sp = context.getSharedPreferences("config", context.MODE_PRIVATE);
        Editor editor = sp.edit();
        editor.putString("username", username);
        editor.putString("password", password);
        editor.commit();
    }
}

主要就是开启edit,然后写数据,然后commit。

SharedPreferences sp = getSharedPreferences("config", MODE_PRIVATE);
        String username = sp.getString("username", "");
        String password = sp.getString("password", "");
        usernameText.setText(username);
        passwordText.setText(password);

上面的是读数据。

我是天王盖地虎的分割线                                                                 

源代码:http://pan.baidu.com/s/1dD1Qx01

savefile_share.zip

 

 

 

 

转载请注明出处:http://www.cnblogs.com/yydcdut/p/3720656.html

相关文章:

  • 2021-09-01
  • 2021-08-19
  • 2021-11-27
  • 2021-07-17
  • 2021-06-18
  • 2019-05-27
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-05-05
  • 2021-08-01
  • 2022-12-23
  • 2021-09-05
  • 2021-04-08
相关资源
相似解决方案