栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 移动开发 > Android

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

Android 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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

本文实例为大家分享了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秒后跳转至应用欢迎界面
}
}

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

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/159235.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号