有关于引导页的使用后再次开启不再使用的demo

来源:互联网 发布:animage软件 编辑:程序博客网 时间:2024/06/05 00:25
/** * @author wangdong * created at 2016/12/5 13:23 */public class SplashActivity extends BaseActivity {    private static final int SHOW_TIME_MIN = 2000;// 最小显示时间    private long mStartTime;// 开始时间    private SharedPreferences.Editor editor;//编辑器    private Intent itGuide;    private Intent ittomain;    private Handler mHandler = new Handler() {        public void handleMessage(android.os.Message msg) {            //暂时设置2秒后进入系统            mHandler.postDelayed(goToMainActivity, SHOW_TIME_MIN);        }    };    /**     * 进入下一个activity的方法     * @param itGuide 跳转的Intent     * @param ittomain 跳转的Intent     */    public void toNextActivity(Intent itGuide, Intent ittomain) {        //从SharedPreferences中获取是否第一次启动   默认为true        boolean fristload = sharedPreferences.getBoolean("fristload", true);        if (fristload) {            //第一次启动进入引导页            startActivity(itGuide);            //第一次启动后,将firstload 置为false 以便以后直接进入主界面不再显示欢迎界面            editor.putBoolean("fristload", false);            editor.commit();     //提交,执行操作        } else {            //进入主界面            startActivity(ittomain);        }    }    Runnable goToMainActivity = new Runnable() {        @Override        public void run() {              /*  SplashActivity.this.startActivity(new Intent(SplashActivity.this,                        GuideActivity.class))*/            ;            toNextActivity(itGuide,ittomain);            finish();        }    };    @Override    protected int getLayoutId() {        return R.layout.act_splash;    }    @Override    protected void initView() {        mStartTime = System.currentTimeMillis();//记录开始时间,        mHandler.sendMessage(new Message());        // 初始化 SharedPreferences 储存        sharedPreferences = getSharedPreferences("check", MODE_PRIVATE);        //创建编辑器        editor = sharedPreferences.edit();    }    @Override    protected void initListener() {    }    @Override    protected void initData() {        //初始化跳转GuideActivity        itGuide = new Intent(this, GuideActivity.class);        // 初始化跳转MainActivity        ittomain = new Intent(this, MainActivity.class);    }}



备注:

sharedPreferences定义在基类中,有关于基类可自行了解

0 0