什么是共享preferences在Android中? [英] What is SharedPreferences in Android?

查看:145
本文介绍了什么是共享preferences在Android中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以请让我清醒有关共享preferences的Andr​​oid系统。 我如何可以设置显示警报消息只有一次,当活动被初始加载的应用程序的条件?

Can anybody please clear me about the SharedPreferences in Android. How can I set a condition of displaying a "Alert Message" only once when the Activity gets loaded initially in the Application?

它是如何通过使用共享preferences做?

How it is done by using SharedPreferences?

Thsnks, 约翰·

Thsnks, John

推荐答案

这是完全巧合,我发誓,我的博客上讲述这个:)

It's completely by coincidence, I swear, that I blogged about this today :)

SharedPreferences settings = this.getSharedPreferences("MyApp",0);
boolean firstrun=settings.getBoolean("firstrun",true);
if (firstrun) {
  SharedPreferences.Editor e = settings.edit();
  e.putBoolean("firstrun",false);
  e.commit();
  // Do something here that you only want to happen the first time
}

这篇关于什么是共享preferences在Android中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆