• android实现应用程序只有在第一次启动时显示引导界面 ,以后就不在显示了


    程序安装后第一次启动:
    启动页-->功能介绍页-->系统主页
    以后启动:
    启动页-->系统主页

    所以在启动页中判断一下就可以了

    可以弄一个文件保存一个状态,推荐用SharedPreferences。

    1.可以定义一个变量来判断程序是第几次运行,如果是第一次则跳转到引导的Activity,如果不是第一次则执行系统主页。

    判断系统是第一次运行的代码实现如下:

    在Activity中添加代码:

    //使用SharedPreferences来记录程序的使用次数

    SharedPreferencespreferences;
    
     
    
       /** Called when the activity is firstcreated. */
    
       @Override
    
       publicvoidonCreate(Bundle savedInstanceState) {
    
            super.onCreate(savedInstanceState);
    
            setContentView(R.layout.main);
    
          
    
            //读取SharedPreferences中需要的数据
    
            preferences = getSharedPreferences("count",MODE_WORLD_READABLE);
    
            int count = preferences.getInt("count", 0);
    
            //判断程序与第几次运行,如果是第一次运行则跳转到引导页面
    
            if (count == 0) {
    
                Intentintent = newIntent();
    
                intent.setClass(getApplicationContext(),BootActivity.class);
    
                startActivity(intent);
    
                finish();
    
            }
    
          
    
            Editor editor = preferences.edit();
    
            //存入数据
    
            editor.putInt("count", ++count);
    
            //提交修改
    
            editor.commit();

    2.还有人说可以这样实现。第一次启动时,因为没SharedPreferences文件,所以为初始化值,比如true要显示,然后在将这个值赋为false,保存后,下次启动是读取SharedPreferences文件,找到值就为false。你在后面写判断要不要显示引导界面就好了。

  • 相关阅读:
    Activeandroid的使用
    Android的数据库ORM框架:Sugar ORM
    Android 快速开发系列 ORMLite 框架最佳实践
    Android ORM 框架之 greenDAO 使用心得
    最受欢迎的5个Android ORM框架
    Android butterknife框架 注解攻略
    强烈推荐android studio用的几个插件
    Android4.0(Phone)来电过程分析
    设计模式入门之装饰器模式Decorator
    VB.NET之错误异常处理
  • 原文地址:https://www.cnblogs.com/xuewater/p/2779449.html
Copyright © 2020-2023  润新知