zoukankan      html  css  js  c++  java
  • 注册界面设计及实现之(三)SharedPerferences实现数据暂存

    开发步骤:

    • 创建一个SharedPerferences接口对象,并使用其putString方法放入相关的公共数据
    • 将验证通过的注册账号写入到该文件中
    • 将数据进行提交
    • 给出客户提示
     1 //Register_Activity.java 
     2 
     3         if (flag) {
     4                         SharedPreferences.Editor editor=getSharedPreferences("publicData",MODE_PRIVATE).edit();//创建一个SharedPerferences接口对象
     5                         editor.putString("account", txtRegAccount.getText().toString().trim());//使用SharedPerferences接口对象的putString方法放入相关的公共数据
     6                         editor.commit();   //将数据进行提交
     7                         Toast.makeText(getApplicationContext(), "新用户注册成功!",Toast.LENGTH_LONG).show();  //给出客户提示
     8                      
     9                         Intent intent = getIntent();
    10                         intent.setClass(Register_Activity.this, LoginActivity.class);
    11                         startActivity(intent);
    12                     }

    在登陆时,要获取SharedPerferences中存在的公共账号数据,代码如下:

    1 //loginActivity.java   
    2       SharedPreferences preferences = getSharedPreferences("publicData",MODE_WORLD_READABLE);
    3         String account= preferences.getString("account","");
    4         this.txtAccount.setText(account);

    运行:

    验证数据文件:

    (1)通过DDMS找到SharedPerferences设置的数据存储文件publicData

    (2)通过File Explorer的导出功能导出publicData.xml

    (3)用记事本打开publicdata.xml,验证其内容

    花朵开放的时候花蕾消逝,人们会说花蕾是花朵否定了的;同样地,当结果的时刻花朵又被解释为植物的一种虚假的存在形式,而果实是作为植物的真实形式而取代花朵的。这些形式不但彼此不同,而且互相排斥,互不相容。但是,他们的流动性却使他们成为有机统一体的环节,他们在有机统一体中不但互相抵触,而且彼此都同样是必要的;而正是这种同样的必要性才构成整体的生命。
  • 相关阅读:
    Sliverlight常见错误集锦
    Excel公式使用
    Slider绑定事件,初始化NullPointerException错误
    修改VS 2012调试默认浏览器
    Silverlight界面设计
    you can't add a reference to Newtonsoft.Json.dll as it was not built against the silverlight runtime
    安装 ArcGISAPI31forSilverlight an i/o error occured while installing a file错误解决
    关于无法进入电子科大信息门户的相关问题研究
    HDU 1878 欧拉回路
    POJ 2492 A Bug's Life
  • 原文地址:https://www.cnblogs.com/zulo/p/5087762.html
Copyright © 2011-2022 走看看