星空网 > 软件开发 > 操作系统

游戏中简单数据存储

在游戏开发中,有时要设置持久的简单数据存储。

Preferences主要是使用简单,但是功能不是很强大,一般适合用于保存一些简单的用户设置的参数,是一种轻量级的存储机制。Preferences仅可以用来存储几种简单类型的数据,如:boolean、int、floate、long、或者String。这些数据以键值对的形式存储在应用程序私有的Preferences目录下的

可以使用 SharedPreferences sp=this.getSharedPreferences("feiruo",Context.MODE_PRIVATE);
或者 SharedPreferences sp=PreferencesManager.getDefaultSharedPreferences(Context);
package com.mycompany.myapp;import android.app.*;import android.os.*;import android.view.*;import android.widget.*;import android.content.*;import java.util.*;public class MainActivity extends Activity{  /** Called when the activity is first created. */  @Override  public void onCreate(Bundle savedInstanceState)  {    super.onCreate(savedInstanceState);    setContentView(R.layout.main);    //获取SharedPreferences引用,存储名为feiruo.    //SharedPreferences sp=PreferencesManager.getDefaultSharedPreferences(this);
    SharedPreferences sp=this.getSharedPreferences("feiruo",Context.MODE_PRIVATE);    String lasttime=sp.getString("time",null);    if(lasttime==null){      lasttime="你好,欢迎第一次光临";    }else{      lasttime="你好,上次登录时间为:"+lasttime;    }    SharedPreferences.Editor ed=sp.edit();    ed.putString("time",new Date().toLocaleString());    ed.commit();//提交修改;    TextView tv=(TextView)this.findViewById(R.id.mainTextView);    tv.setText(lasttime);  }}

 




原标题:游戏中简单数据存储

关键词:

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

TikTok电商引流 | 被低估的高流量标签:毕业季:https://www.goluckyvip.com/news/10109.html
货物被海关查扣_卖家拒付运费_物流商有哪些维权途径:https://www.goluckyvip.com/news/1011.html
Amazon Live和TikTok Live对比分析 :https://www.goluckyvip.com/news/10110.html
跨境物流有哪些常用贸易术语? :https://www.goluckyvip.com/news/10111.html
掌握Lazada、Shopee店铺运营的黄金法则:测评自养号技巧 :https://www.goluckyvip.com/news/10112.html
反诈!跨境电商新型骗局Lazada假冒网站 大量虚假订单,商家必看:https://www.goluckyvip.com/news/10113.html
深圳到西安自驾路线攻略 深圳到西安自驾最佳路线:https://www.vstour.cn/a/411228.html
松花蛋是哪里的特产松花蛋的产地:https://www.vstour.cn/a/411229.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流