原理是这样,我们在SharedPreferences中存储一个int型数据,用来代表第几次登录,每次启动时都读取出来判断是不是第一次启动,然后依次判断是否要显示欢迎界面,

具体实现如下:

设置一个欢迎界面的Activity,并设置为主Activity,在判断第几次启动后来决定要不要跳转到MainActivity

package com.example.f;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.Button; public class StartActivity extends AppCompatActivity {
private Button go=null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_start); go=(Button)findViewById(R.id.go);
SharedPreferences userInfo = getSharedPreferences("start", MODE_PRIVATE);
SharedPreferences.Editor editor = userInfo.edit();
Int x;
//获取记录启动次数的值,若获取不到就默认为1
x=userInfo.getInt("start",1);
//判断第几次启动
if(x==1)
{
//为启动数加一
x++;
editor.putInt("start",x);
editor.commit(); }
else {
//若不是第一次登录就直接跳转MainActivity
x++;
editor.putInt("start",x);
editor.commit();
Intent it=new Intent();
it.setClass(StartActivity.this,MainActivity.class);
startActivity(it);
StartActivity.this.finish();
}
//欢迎界面进入应用的按钮
go.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent it=new Intent();
it.setClass(StartActivity.this,MainActivity.class);
startActivity(it);
StartActivity.this.finish(); }
});
}
}

  布局文件只有一个按钮

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".StartActivity"> <Button
android:id="@+id/go"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="开始"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

  初次启动效果如下

Android应用第一次启动时的欢迎界面制作的更多相关文章

  1. android应用程序第一次启动时显示引导界面

    市面上好多优秀的应用(举例新浪微博.UC浏览器)都采用了欢迎页面与使用向导的方式给用户带来了良好的用户体验. 一般来说用户第一次安装应用或者安装了新版本后第一次进入应用都会显示成 欢迎页面-使用向导- ...

  2. android实现应用程序仅仅有在第一次启动时显示引导界面

    概述 SharedPreferences的使用很easy,可以轻松的存放数据和读取数据.SharedPreferences仅仅能保存简单类型的数据,比如,String.int等.通常会将复杂类型的数据 ...

  3. Android Studio的安装及第一次启动时的配置

    Android Studio的安装及第一次启动时的配置 一.下载Android Studio 百度搜索“Android Studio" 点击中文社区进入,选择最新版本下载. 下载后双击安装包 ...

  4. uni-app开发经验分享十二: Android平台应用启动时读写手机存储、访问设备信息(如IMEI)等权限策略及提示信息

    Android平台从6.0(API23)开始系统对权限的管理更加严格,所有涉及敏感权限都需要用户授权允许才能获取.因此一些应用基础业务逻辑需要的权限会在应用启动时申请,并引导用户允许. 读写手机存储权 ...

  5. Android应用程序启动时发生AndroidRuntime : ClassNotFoundException for Activity class的解决方法

    在android应用程序启动时抛出下面异常导致启动失败:07-09 17:12:35.709: ERROR/AndroidRuntime(3866): Uncaught handler: thread ...

  6. 【Android端 APP 启动时长获取】启动时长获取方案及具体实施

    一.什么是启动时长? 1.启动时长一般包括三种场景,分别是:新装包的首次启动时长,冷启动时长.热启动时长 冷启动 和 热启动 : (1)冷启动:当启动应用时,后台没有该程序的进程,此时启动的话系统会分 ...

  7. Android Studio 第一次启动配置

    第一次启动AS前,为了避免重新下载新版本的SDK 操作如下: AS启动前,请先将bin目录的idea.properties文件中增加一行:disable.android.first.run=true ...

  8. Android Studio第一次启动失败的解决办法

    Android Studio Android 开发环境 由于GFW的问题,安装后第一次启动会在显示Fetching android sdk component information对话框后,提示错误 ...

  9. freshStartTail 第一次启动时 抛弃旧的日志

    freshStartTail [on/off] (requires v8.18.0+) Default: off This is used to tell rsyslog to seek to the ...

随机推荐

  1. 机器学习笔记P1(李宏毅2019)

    该博客将介绍机器学习课程by李宏毅的前两个章节:概述和回归. 视屏链接1-Introduction 视屏链接2-Regression 该课程将要介绍的内容如下所示: 从最左上角开始看: Regress ...

  2. django中navie time 和 aware time的使用和转换

    在django中有关时间被分为navie time 和 aware time两种,前者指的是不带时区标记的时间格式,后者被认为是带有时区标记的时间格式.在django框架的setting.py文件中 ...

  3. MybatisDao

    一.mybatisDao的编写(原始方式,不用) 1.接口编写 public interface UserDao { public void save(User user); public User ...

  4. 用tensorflow构建神经网络学习简单函数

    目标是学习\(y=2x+3\) 建立一个5层的神经网络,用平方误差作为损失函数. 代码如下: import tensorflow as tf import numpy as np import tim ...

  5. Educational Codeforces Round 57

    2018.12.28  22:30 看着CF升高的曲线,摸了摸自己的头发,我以为我变强了,直到这一场Edu搞醒了我.. 从即将进入2018年末开始,开启自闭场集合,以纪念(dian)那些丢掉的头发 留 ...

  6. Expect & Shell: 网络设备配置备份

    1. 环境介绍及效果展示 A. centos 6.6 x64 B. tftp-server 0.49 C. 脚本目录 D. 备份目录 E. 备份邮件 2. tftp服务配置 A. [root@step ...

  7. Shiro自动登录

    Shiro RememberMe spring.xml <bean class="org.apache.shiro.web.mgt.DefaultWebSecurityManager& ...

  8. Go语言实现:【剑指offer】变态跳台阶

    该题目来源于牛客网<剑指offer>专题. 一只青蛙一次可以跳上1级台阶,也可以跳上2级--它也可以跳上n级.求该青蛙跳上一个n级的台阶总共有多少种跳法. 找规律: 1阶:1种: 2阶:2 ...

  9. Go语言实现:【剑指offer】二叉树的下一个结点

    该题目来源于牛客网<剑指offer>专题. 给定一个二叉树和其中的一个结点,请找出中序遍历顺序的下一个结点并且返回. 注意,树中的结点不仅包含左右子结点,同时包含指向父结点的指针. Go语 ...

  10. 如何查看SparkSQL 生成的抽象语法树?

    前言 在<Spark SQL内核剖析>书中4.3章节,谈到Catalyst体系中生成的抽象语法树的节点都是以Context来结尾,在ANLTR4以及生成的SqlBaseParser解析SQ ...