Android Studio SharedPreferences的使用

存储位置

SharedPreferences以键值对的形式,存放在设备/data/data/<package name>/shared_prefs/data.xml中,保存的数据会随着应用的卸载而被删除

存储数据

java 复制代码
// 导入
import android.content.SharedPreferences;

// 获取SharedPreferences对象
SharedPreferences sp = (SharedPreferences) getSharedPreferences("data",MODE_PRIVATE);
// 获取Editor对象
SharedPreferences.Editor editor = sp.edit();
// 将值以字符串形式存入
editor.putString("userName", user_name.getText().toString());
editor.putString("password", password.getText().toString());
// 提交数据
editor.commit();
Toast.makeText(MainActivity.this,"注册成功",Toast.LENGTH_SHORT).show();

提取数据

相关推荐
我狸才不是赔钱货1 小时前
VsCode + Wsl:终极开发环境搭建指南
ide·vscode·编辑器
消失的旧时光-19434 小时前
Flutter 响应式 + Clean Architecture / MVU 模式 实战指南
android·flutter·架构
404未精通的狗4 小时前
(数据结构)栈和队列
android·数据结构
恋猫de小郭5 小时前
今年各大厂都在跟进的智能眼镜是什么?为什么它突然就成为热点之一?它是否是机会?
android·前端·人工智能
游戏开发爱好者87 小时前
iOS 混淆工具链实战 多工具组合完成 IPA 混淆与加固 无源码混淆
android·ios·小程序·https·uni-app·iphone·webview
豆豆豆大王12 小时前
Android 数据持久化(SharedPreferences)
android
Paper_Love12 小时前
RK3588-android-reboot命令内核调用流程
android
介一安全12 小时前
【Frida Android】基础篇12:Native层hook基础——调用原生函数
android·网络安全·逆向·安全性测试·frida·1024程序员节
2501_9160088913 小时前
用多工具组合把 iOS 混淆做成可复用的工程能力(iOS混淆|IPA加固|无源码混淆|Ipa Guard|Swift Shield)
android·开发语言·ios·小程序·uni-app·iphone·swift
Zach_yuan13 小时前
程序地址空间
android·linux·运维·服务器