<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.sample3_6"
android:versionCode="1"
android:versionName="1.0" > <uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" /> <application
android:allowBackup="true"
android:icon="@drawable/icon"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.sample3_6.MyActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application> </manifest>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="25dip"
android:id="@+id/TextView01" /> <!-- 添加TextView -->
</LinearLayout>
package com.example.sample3_6;

import java.security.acl.LastOwnerException;
import java.util.Date; import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.view.Menu;
import android.view.View;
import android.widget.TextView; public class MyActivity extends Activity { private TextView tv; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
SharedPreferences sp = this.getSharedPreferences("sharePre", Context.MODE_PRIVATE);
String lastLogin = sp.getString(
"ll", //键值
null //默认值
);
if(lastLogin ==null){
lastLogin = "欢迎您,您是第一次访问本Preferences";
}else{
lastLogin = "欢迎回来,您上次于" + lastLogin + "登录";
}
SharedPreferences.Editor editor = sp.edit();
editor.putString("ll", new Date().toLocaleString());
editor.commit();
tv = (TextView) this.findViewById(R.id.TextView01);
tv.setText(lastLogin); /* @Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
*/
}
}

3.4 存储简单数据的利器——Preferences的更多相关文章

  1. Electron存储简单数据和用户首选项推荐用electron-store

    electron-store1可以用来保存Electron应用程序或模块的简单数据持久性-保存和加载用户首选项,应用程序状态,缓存等. 1https://github.com/sindresorhus ...

  2. Android简单数据存储SharedPreferences

    SharedPreferences是Android中存储简单数据的一个工具类.可以想象它是一个小小的Cookie,它通过用键值对的方式把简单数据类型(boolean.int.float.long和St ...

  3. Atitit 数据存储的数据表连接attilax总结

    Atitit 数据存储的数据表连接attilax总结 1.1. 三种物理连接运算符:嵌套循环连接.合并连接以及哈希连接1 1.2. a.嵌套循环连接(nested loops join)1 1.3. ...

  4. cocos2d-x中使用可加密Sqlite存储玩家数据

    手机游戏当中的数据存储是一个重要的课题.cocos2d-x发展到现在的版本2.1.4,已经直接实现了对sqlite的支持(extensions/LocalStorage),这对我们一般的数据存储已经够 ...

  5. Memcache存储大量数据的问题

    Memcache存储大数据的问题  huangguisu Memcached存储单个item最大数据是在1MB内,假设数据超过1M,存取set和get是都是返回false,并且引起性能的问题. 我们之 ...

  6. MongoDB应用案例:使用 MongoDB 存储日志数据

    线上运行的服务会产生大量的运行及访问日志,日志里会包含一些错误.警告.及用户行为等信息,通常服务会以文本的形式记录日志信息,这样可读性强,方便于日常定位问题,但当产生大量的日志之后,要想从大量日志里挖 ...

  7. Postgres 优雅存储树形数据

    碰到一个树形数据需要存储再数据控制,碰到以下两个问题: 在PG数据库中如何表达树形数据 如何有效率的查询以任意节点为Root的子树 测试数据 为了更加简单一些,我们将使用一下数据 Section A ...

  8. 【转】Syncthing – 数据同步利器---自己的网盘,详细安装配置指南,内网使用,发现服务器配置

    Syncthing – 数据同步利器---自己的网盘,详细安装配置指南,内网使用,发现服务器配置 原贴:https://www.cnblogs.com/jackadam/p/8568833.html ...

  9. 使用 MongoDB 存储日志数据

    使用 MongoDB 存储日志数据     线上运行的服务会产生大量的运行及访问日志,日志里会包含一些错误.警告.及用户行为等信息.通常服务会以文本的形式记录日志信息,这样可读性强,方便于日常定位问题 ...

随机推荐

  1. C#使用Win32函数的一些类型转换

    C#在访问Win 32 Api时需要处理C 结构与C#结构的映射,这在MSDN以及许多Blog上都可以找到参考的资料.Win 32 中有一些定义复杂的Struct,这些结构体拥有长度固定的数组或者一些 ...

  2. C# 获取表中最大值

    ; if (db.LPicture.Any()) { // LPicture Newmode = db.LPicture.Where(n => ).FirstOrDefault(); start ...

  3. VUE路由history模式坑记--NGINX

    因微信分享和自动登录需要,对于URL中存在'#'的地址,处理起来比较坑(需要手动写一些代码来处理).还有可能会有一些隐藏的问题没被发现. 如果VUE能像其他(JSP/PHP)系统的路径一样,就不存在这 ...

  4. linux中集群的免秘钥SSH直接登录

    这里以三台mysql的主从服务器为例:manage.master.slave1.slave2   给4个机器生成秘钥文件 以manage为例,执行命令,生成空字符串的秘钥(后面要使用公钥),命令是: ...

  5. PAT_A1107#Social Clusters

    Source: PAT A1107 Social Clusters (30 分) Description: When register on a social network, you are alw ...

  6. Bequeath Connection and SYS Logon

    The following example illustrates how to use the internal_logon and SYSDBA arguments to specify the ...

  7. 通过git向github提交项目

    按顺序学习 https://www.cnblogs.com/forget406/p/6045499.html#top https://blog.csdn.net/xiaoputao0903/artic ...

  8. Java 内存模型与线程

    when ? why ? how ? what ? 计算机的运行速度和它的存储和通信子系统速度的差距太大,大量的时间都花费在磁盘I/O .网络通信或者数据库访问上.如何把处理器的运算能力"压 ...

  9. 【MFC Programming】 Using Dialog To Set A Correlate Menu

    This blog will show how to display a menu we designed in a dialog. 1.Insert a new dialog& a new ...

  10. Redis学习总结(2)——Java使用Redis

    安装 开始在 Java 中使用 Redis 前, 我们需要确保已经安装了 redis 服务及 Java redis 驱动,且你的机器上能正常使用 Java. Java的安装配置可以参考我们的 Java ...