写着写着代码就突然想到了这个,先记下来吧,有需要的可以直接拿走
利用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();