引导页之SharedPreferences的使用

 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)欢迎各位纠正错误,评论,吐槽!!!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值