1.存储
源码:
SharedPreferences sp = getApplicationContext().getSharedPreferences("USER", MODE_PRIVATE) ;//
Editor editor = sp.edit() ;
editor.putString("USERNAME", username) ;//username为字符串参数
editor.putString("PASSWORD", password) ;//password为字符串参数
SharedPreferences sp = getApplicationContext().getSharedPreferences("USER", MODE_PRIVATE) ;
String username = sp.getString("USERNAME", "") ;
String password = sp.getString("PASSWORD", "") ;
源码:
SharedPreferences sp = getApplicationContext().getSharedPreferences("USER", MODE_PRIVATE) ;//
Editor editor = sp.edit() ;
editor.putString("USERNAME", username) ;//username为字符串参数
editor.putString("PASSWORD", password) ;//password为字符串参数
editor.commit() ;//提交
SharedPreferences sp = getApplicationContext().getSharedPreferences("USER", MODE_PRIVATE) ;
String username = sp.getString("USERNAME", "") ;
String password = sp.getString("PASSWORD", "") ;
本文详细介绍了如何使用 Android 的 SharedPreferences 进行数据存储和读取。包括设置 SharedPreferences 的实例,通过编辑器存储用户名和密码,以及如何从 SharedPreferences 中读取这些数据。
1947

被折叠的 条评论
为什么被折叠?



