当前位置:首页 > Android > 正文内容

Android SharedPreferences的简单使用

4年前 (2021-03-12)Android

Android的SharedPreferences与iOS的UserDefaults.standard十分相同,都是是保存一些轻量配置数据的地方。

这里假设保存用户名

SharedPreferences sp = mContext.getSharedPreferences("mysp", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sp.edit();
editor.putString("username", username);
editor.putString("passwd", passwd);
editor.commit();

提取已保存的值

SharedPreferences sp = mContext.getSharedPreferences("mysp", Context.MODE_PRIVATE);
String username = sp.getString("username", "");


扫描二维码推送至手机访问。

版权声明:本文由小祥子的博客发布,如需转载请注明出处。

本文地址:http://www.xiaoxiangzi.com/post/90.html

相关文章

Android 网络请求后的JSON解析

JSON解析用阿里巴巴的fastjson。implementation 'com.alibaba:fastjson:1.1.71.android' 根据上一篇文章,登录接口登...

Activity的生命周期与iOS UIViewController对比

一个页面或APP的生命周期,对开发尤为重要,知道生命周期,才知道代码应该写在哪里。刚开始学iOS的时候,也因为没有深入了解页面的生命周期导致出了一些奇怪的bug。Android Activity的生命...

安卓 获取TextView手指点击所在位置的文字

TextView tv;     public final static String HTML_TEX...

Android 网络请求 Kalle

APP作为前端,比较核心的功能算是网络请求了,这里用Kalle,这个第三方的网络请求框架。implementation 'com.yanzhenjie:kalle:0.1.7'&nbs...

Android Intent界面之间的跳转

当前页面跳转到NextActivity页面Intent intent = new Intent(this,NextActivity.class) this.s...

Android PopupWindow的基本使用

需求:希望点击文本区域的时候,在手指处添加一个控件,开始想到的是相对布局,添加一个隐藏层,根据点击然后显示并且重设坐标,后来发现这个方向是错的,甚至有点蠢,后来看到了popupWindow。Popup...