Android中SharedPreferences的使用

SharedPreferences 使用详解 和你一起终身学习,这里是程序员Android经典好文推荐,通过阅读本文,您将收获以下知识点:一、 SharedPreferences 简介二、SharedPreferences 保存数据的方法三、SharedPreferences读取数据的方法四、总结SharePerference Utils 封装类使用方法五、SharedPreferences 数据保存位置一、 SharedPreference... 阅读详情

获取SharedPreferences的两种方式:

1 调用Context对象的getSharedPreferences()方法
2 调用Activity对象的getPreferences()方法

两种方式的区别:

调用Context对象的getSharedPreferences()方法获得的SharedPreferences对象可以被同一应用程序下的其他组件共享.
调用Activity对象的getPreferences()方法获得的SharedPreferences对象只能在该Activity中使用.

SharedPreferences的四种操作模式:
Context.MODE_PRIVATE
Context.MODE_APPEND
Context.MODE_WORLD_READABLE
Context.MODE_WORLD_WRITEABLE

Context.MODE_PRIVATE:为默认操作模式,代表该文件是私有数据,只能被应用本身访问,在该模式下,写入的内容会覆盖原文件的内容
Context.MODE_APPEND:模式会检查文件是否存在,存在就往文件追加内容,否则就创建新文件.
Context.MODE_WORLD_READABLE和Context.MODE_WORLD_WRITEABLE用来控制其他应用是否有权限读写该文件.
MODE_WORLD_READABLE:表示当前文件可以被其他应用读取.
MODE_WORLD_WRITEABLE:表示当前文件可以被其他应用写入.
将数据保存至SharedPreferences:
SharedPreferences preferences=getSharedPreferences(“user”,Context.MODE_PRIVATE);
Editor editor=preferences.edit();
String name=”xixi”;
String age=”22”;
editor.putString(“name”, name);
editor.putString(“age”, age);
editor.commit();

从SharedPreferences获取数据:
SharedPreferences preferences=getSharedPreferences(“user”, Context.MODE_PRIVATE);
String name=preferences.getString(“name”, “defaultname”);
String age=preferences.getString(“age”, “0”);

基于卷积神经网络CNN实现电力负荷多变量时序预测(PyTorch版) 随着智能电网的发展,精准的电力负荷预测对能源调度和电网稳定具有重要意义。本文基于PyTorch框架,提出一种基于卷积神经网络(CNN)的多变量时间序列预测模型,用于电力负荷的短期预测。 阅读详情

相关推荐

当NetApp 7-mode遇到单控制器故障:HA模式手动修复全记录

本文详细记录了NetApp 7-mode存储系统在单控制器故障时的应急修复过程,包括HA配置重建、磁盘初始化和业务恢复等关键步骤。通过实战案例解析如何解决`VIA Interconnect is down`等典型问题,为企业级存储系统的高可用保障提供实用指南。

yolo5detector的博客 246

Android SharedPreferences使用详解

Android学习笔记之数据存储

jpfice的博客 1649

matplotlib三维画图之观察博弈论混合策略下纳什均衡点

参考链接: 博弈论入门20讲之第16讲-猜谜游戏-散户如何赢庄家 游戏背景: 我的期望是: 你的期望是: 使用Python的matplotlib画图: import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D fig = plt.figure() ax = Axes3D(fig) X = np.linspace(0, 1, 100) Y = np.linspace(0, 1,

敲代码的小风 1258

Android-SharedPreferences详细使用

通过利用SharedPreferences来存储用户的用户名和密码,以此来达到用户打开APP时同步登录、记住密码一键登录的需求/效果

qq_50726065的博客 1856

告别手动核对!用这个ABAP报表一键导出所有物料的库存与需求清单

本文介绍了如何通过定制化ABAP报表一键导出SAP系统中所有物料的库存与需求清单,整合MD04、MB52、ME2N等多个事务码的数据,大幅提升供应链管理和生产计划效率。该报表可自动生成包含库存状态、MRP需求、采购订单等关键指标的物料全景视图,帮助企业减少手工操作错误,节省时间成本。

weixin_33725515的博客 467

光伏逆变器在环测试解决方案

光伏行业是利用太阳能光辐射将其转化为可用电能的行业。近年来,为应对气候变化和能源安全等挑战,全球对清洁能源的需求不断增长。太阳能作为最具潜力和可再生的能源之一,被视为替代传统化石能源的重要选择,光伏行业因此得到了迅猛发展,并在全球范围内得到了广泛应用。许多国家和地区都将光伏技术作为关键的能源发展方向。尤其是在新兴和发展中国家,光伏发电具有巨大的增长潜力,将成为未来市场竞争的重点。随着规模化生产的推进,光伏组件的制造成本不断降低。

shiwei0813的博客 959

Android中SharedPreferences 的基本使用

SharedPreferences 是 Android 平台为应用开发者提供的一个轻量级的存储辅助类,用来保存应用的一些常用配置,它提供了 putString()、putString(Set)、putInt()、putLong()、putFloat()、putBoolean() 六种数据类型。数据最终是以 XML 形式进行存储,产生的文件保存在/data/data/应用包名/shared_prefs目录下,是日常开发非常常用的一个数据存储类。

huaqianzkh的专栏 2165

一文搞懂深度学习:最全神经网络介绍

本文是深度学习系列文章的第二篇,我们将深入探讨各种类型的人工神经网络,探索它们独特的特性和应用。

2402_82802238的博客 2800

Android开发入门——SharedPreferences的使用

//_** 姓名* 默认值:false*/2.创建SharedPreferences的帮助类这个类主要作为各个SharedPreferences的生产工厂使用,并进一步提供简化的提交,获取值的方法。//用户相关的SP/**用户相关Sp相关的key见{@link SpKeyUser}*//**用户相关Sp相关的key见{@link SpKeyDefault}*///sharedPreferences 是否为空/***//**具有默认值。

2401_84123077的博客 1245

Vivado XDMA仿真实战:从配置到链路训练全解析

本文深入解析了Vivado中XDMA IP核的仿真实战流程,重点剖析了PCIe链路训练状态机(LTSSM)的工作原理与调试方法。通过搭建仿真环境、解读日志与波形,手把手指导如何从配置、链路训练(LTSSM)到BAR映射与DMA启动进行全流程分析与问题定位,帮助工程师掌握核心调试技能,确保PCIe链路稳定与数据传输正确。

weixin_29197051的博客 154

告别调参玄学:用 DINOv2 (ViT-S/ViT-G) 和 PCA 可视化,直观理解自监督特征

本文深入解析了DINOv2(ViT-S/ViT-G)模型在自监督学习中的特征提取机制,通过PCA降维技术实现特征空间的可视化。文章对比了不同规模模型的特征表达差异,并提供了PCA阈值调优和深度分析的实用技巧,帮助读者直观理解自监督学习的视觉密码。

weixin_42565865的博客 409

安卓SharedPreferences类的使用

1 package com.lidaochen.phonecall; 2 3 import android.content.Intent; 4 import android.content.SharedPreferences; 5 import android.net.Uri; 6 import android.os.Environment; 7 impo...

weixin_30726161的博客 164

手把手教你用 Cursor 写一个完整的 Web 应用(含前后端 + 部署)

本文介绍如何利用Cursor AI工具从零开发一个完整的全栈待办事项Web应用。文章针对开发者常见痛点——无法独立完成项目闭环,提供了一套AI驱动的全栈开发范式。通过Vue3+Node.js+MySQL技术栈,全程由Cursor自动生成项目架构、前后端代码、数据库设计,并解决联调、部署等关键问题。重点展示了如何用AI完成:项目规划与架构设计、后端接口开发、前端页面实现、跨域联调、打包优化及云端部署全流程。该方法将传统需要3-5天的开发工作压缩至1小时内完成,产出规范可上线的项目,特别适合想突破"碎

远程部署调试 运行安装 项目调试 二次开发 项目技术新 持续迭代 部分源码免费分享 633

使用Kotlin的Android SharedPreferences

In this tutorial, we’ll learn how to implement SharedPreferences in our Android Application using Kotlin. 在本教程中,我们将学习如何使用Kotlin在Android应用程序中实现SharedPreferences。 什么是Android SharedPreferences? (What i...

从零开始的教程世界 3105

SIMATIC S7-1200, S7-1500 PID 控制[手册]

SIMATIC S7-1200, S7-1500 PID 控制[手册]

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

安卓SharedPreferences使用

安卓SharedPreferences使用

似霰的博客 1458

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Android SharedPreferences的使用

SharedPreferences是Android平台上一个轻量级的存储类,主要是保存一些常用的配置比如窗口状态,一般在Activity中 重载窗口状态onSaveInstanceState保存一般使用SharedPreferences完成,它提供了Android平台常规的Long长 整形、Int整形、String字符串型的保存,它是什么样的处理方式呢?SharedPreferences类似过去W

小小程序员 欢迎光临!专注于移动互联网! 7万+

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

安卓SharedPreferences的使用

   安卓中的SharedPreferences可以用来保存一些很小的数据,比如一个应用的账户信息等,我们的QQ登录中记住账号和密码这个功能就是通过这个实现的。这里不讲简介这些,就记录一下怎么进行使用 实现步骤: 通过Context获取sharedPreferences对象 通过editor()方法获取Editor对象 通过Editor对象对键值对数据进行增加删除等操...

alex_wen2014的博客 589

SharedPreferences的使用,android

SharedPreferences的使用 <?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.an...

苏凯的博客 472

安卓开发工程师-SharedPreferences 使用

是 Android 提供的一种轻量级的存储类,用于存储简单的键值对数据。它基于 XML 文件存储数据,每个应用都有自己的。数据默认存储在应用的私有目录下,无法被其他应用访问。如果需要更高的安全性,可以对数据进行加密。对于复杂数据结构,可以将其序列化为 JSON 或其他格式后存储。中,例如用户的登录状态、上次访问时间等。可以通过指定相同的文件名来共享。中,例如字体大小、主题颜色等。中,例如应用的主题、语言等。可以将用户的偏好设置存储在。可以将配置信息存储在。接口来监听数据变化。可以将临时数据存储在。

qq_62784677的博客 804

android sharedpreferences简单使用,Android中SharedPreferences简单使用实例

本文实例为大家分享了SharedPreferences简单使用案例,供大家参考,具体内容如下MainActivity:public class SharedPreferencesTestActivity extends Activity implements View.OnClickListener{private EditText editText;private TextView textVi...

weixin_36413247的博客 233

android SharedPreferences 使用

android提供了五种存储数据的方式,分别是:SharedPreferences、文件存储、Sqlite数据库、ContentProvider以及网络存储数据,在本文中,我们将介绍一下SharedPreferences的使用。

米歌留白 679

Android使用SharedPreferences存储数据

Android官方api:SharedPreferences类提供了一个通用框架,以便您能够保存和检索原始数据类型的永久性键值对。您可以使用SharedPreferences来保存任何原始数据:布尔值,浮点值,整型值,长整型和字符串。此数据将跨多个用户会话永久保留(即使您的应用已终止亦如此)。 详解:SharedPreferences使用xml格式为Android应用提供一种永久数据存贮方式,并且...

计蒙不吃鱼的博客 8015

Android,SharedPreferences的使用

SharedPreferences是一个轻量级存储框架,以“key-value键值对”的形式来保存数据,默认存储在/data/data//shared_prefs目录下。

qq_46269365的博客 1039
上一篇: SpringBOOT入门
下一篇: Spring拦截器使用
aNoobCoder
博客等级 码龄10年 2粉丝 52原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值