当前位置: 移动技术网 > IT编程>移动开发>Android > Android判断程序是否第一次启动

Android判断程序是否第一次启动

2019年07月24日  | 移动技术网IT编程  | 我要评论

点点英语,魔易乾坤,萧如瑟五十弦

本文实例为大家分享了android判断程序是否第一次启动的具体代码,供大家参考,具体内容如下

public class welcome extends activity {
  private final long splash_length = 2000;
  handler handler = new handler();

  public void oncreate(bundle savedinstancestate) {
    super.oncreate(savedinstancestate);
    setcontentview(r.layout.farst_img);
    
    //定义一个setting记录app是几次启动!!!
    sharedpreferences setting = getsharedpreferences("com.example.hr_jie", 0);
    boolean user_first = setting.getboolean("first", true);
    if (user_first) {// 第一次则跳转到欢迎页面
      setting.edit().putboolean("first", false).commit();
      tiaozhuanzhu();
    } else {//如果是第二次启动则直接跳转到主页面
      tiaozhuanfu();
    }
  }
  
  public void tiaozhuanzhu(){ 
  handler.postdelayed(new runnable() { //使用handler的postdelayed实现延时跳转 
     
      public void run() {  
        intent intent = new intent(welcome.this, welcome_four.class);  
        startactivity(intent);  
        finish();    
      }  
    }, splash_length);//2秒后跳转至应用主界面mainactivity 
}
  
  public void tiaozhuanfu(){ 
  handler.postdelayed(new runnable() {//使用handler的postdelayed实现延时跳转 
     
      public void run() {  
        intent intent = new intent(welcome.this, mainactivity.class);  
        startactivity(intent);  
        finish();    
      }  
    }, splash_length);//2秒后跳转至应用欢迎界面
}
}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持移动技术网。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网