您的位置:首页 > Web前端

引导页之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)欢迎各位纠正错误,评论,吐槽!!!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: