Android 判断软件是否第一次打开

写着写着代码就突然想到了这个,先记下来吧,有需要的可以直接拿走

利用SharedPreferences可以实现,等以后用到别的再记下来

onCreate里面

SharedPreferences setting = getSharedPreferences("com.gzyyu.buyeasy", 0);
        Boolean first = setting.getBoolean("FIRST", true);
        if (user_first) {// 第一次则跳转到注册页面
            setting.edit().putBoolean("FIRST", false).commit();
            firstLoad();
        } else {//如果是第二次启动则直接跳转到主页面
            noFirstLoad();
        }

两个返回值

private void noFirstLoad() {
        // 使用Handler的postDelayed方法,3秒后执行跳转到MainActivity
        handler.postDelayed(new Runnable() {
            public void run() {
                Intent intent = new Intent(LaunchActivity.this, MainActivity.class);
                startActivity(intent);
                finish();
            }
        }, SPLASH_DELAY_MILLIS);

    }

    private void firstLoad() {
        handler.postDelayed(new Runnable() {  //使用handler的postDelayed实现延时跳转

            public void run() {
                Intent intent = new Intent(LaunchActivity.this, SignupActivity.class);
                startActivity(intent);
                finish();
            }
        }, SPLASH_DELAY_MILLIS);//2秒后跳转至应用主界面MainActivity
    }

忘了还有两个private先声明

private static final long SPLASH_DELAY_MILLIS = 3000;
Handler handler = new Handler();
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值