引导页之SharedPreferences的使用
2015-12-15 09:27
387 查看
btnStart.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //更新sp,表示已展示 SharedPreferences sp = getSharedPreferences("config",MODE_PRIVATE); sp.edit().putBoolean("is_use_guide_page",true).commit(); /** 替换 PrefUtils.setBoolean(GuideActivity.this,"is_use_guide_page",true); */ //跳转页面 startActivity(new Intent(GuideActivity.this, MainActivity.class)); finish(); } });
闪屏page
//设置动画监听 set.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { } //动画结束 @Override public void onAnimationEnd(Animation animation) { // SharedPreferences sp = SharedPreferences(); jumpNextPage(); } @Override public void onAnimationRepeat(Animation animation) { } }); rlRoot.startAnimation(set); } /** * 跳转到下一个页面 */ private void jumpNextPage(){ //判断之前有没有显示过新手引导界面 SharedPreferences sp = getSharedPreferences("config",MODE_PRIVATE); boolean userGuide = sp.getBoolean("is_use_guide_page",false); /** 替换 boolean userGuide = PrefUtils.getBoolean(this,"is_use_guide_page",false); */ // 跳转到新手引导页 if(userGuide){ startActivity(new Intent(SplashActivity.this, GuideActivity.class)); }else{ startActivity(new Intent(SplashActivity.this, MainActivity.class)); } finish(); }
封装sharePreference
/** * SharePreference封装 */ public class PrefUtils { public static final String PREF_NAME = "config"; public static boolean getBoolean(Context ctx,String key,boolean defaultValue){ //判断之前有没有显示过新手引导界面 SharedPreferences sp = ctx.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE); return sp.getBoolean(key,defaultValue); } public static void setBoolean(Context ctx,String key,boolean defaultValue){ //判断之前有没有显示过新手引导界面 SharedPreferences sp = ctx.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE); boolean userGuide = sp.edit().putBoolean(key,defaultValue).commit(); } }
传承者(Inheritors)欢迎各位纠正错误,评论,吐槽!!!
相关文章推荐
- Js中实现数组的排序、乱序、搜索 、去重和删除
- JSP入门之自定义标签
- js修改onclick动作的四种方式
- 【剑指offer】之字符串的排列
- three.js学习计划(一)
- leetcode Remove Nth Node From End of List
- 使用 angular directive 和 json 数据 D3 随着标签 donut chart演示样本
- jquery九宫格抽奖转盘插件
- Jquery easyui从零单排之datagrid单行数据删除
- javascript用法
- 9个超绚丽的HTML5 3D图片动画特效
- maven打包在MANIFEST.MF文件中增加属性
- js中json字符串的处理
- Json字符串解析不了,解析对象为null
- js编写“贪吃蛇”的小游戏
- Javascript闭包函数快速上手
- Javascript闭包函数快速上手
- NameNode 自动重启问题排查
- HTMl5的存储方式sessionStorage和localStorage详解
- Javascript闭包函数快速上手