Android应用第一次启动时的欢迎界面制作
原理是这样,我们在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应用第一次启动时的欢迎界面制作的更多相关文章
- android应用程序第一次启动时显示引导界面
市面上好多优秀的应用(举例新浪微博.UC浏览器)都采用了欢迎页面与使用向导的方式给用户带来了良好的用户体验. 一般来说用户第一次安装应用或者安装了新版本后第一次进入应用都会显示成 欢迎页面-使用向导- ...
- android实现应用程序仅仅有在第一次启动时显示引导界面
概述 SharedPreferences的使用很easy,可以轻松的存放数据和读取数据.SharedPreferences仅仅能保存简单类型的数据,比如,String.int等.通常会将复杂类型的数据 ...
- Android Studio的安装及第一次启动时的配置
Android Studio的安装及第一次启动时的配置 一.下载Android Studio 百度搜索“Android Studio" 点击中文社区进入,选择最新版本下载. 下载后双击安装包 ...
- uni-app开发经验分享十二: Android平台应用启动时读写手机存储、访问设备信息(如IMEI)等权限策略及提示信息
Android平台从6.0(API23)开始系统对权限的管理更加严格,所有涉及敏感权限都需要用户授权允许才能获取.因此一些应用基础业务逻辑需要的权限会在应用启动时申请,并引导用户允许. 读写手机存储权 ...
- Android应用程序启动时发生AndroidRuntime : ClassNotFoundException for Activity class的解决方法
在android应用程序启动时抛出下面异常导致启动失败:07-09 17:12:35.709: ERROR/AndroidRuntime(3866): Uncaught handler: thread ...
- 【Android端 APP 启动时长获取】启动时长获取方案及具体实施
一.什么是启动时长? 1.启动时长一般包括三种场景,分别是:新装包的首次启动时长,冷启动时长.热启动时长 冷启动 和 热启动 : (1)冷启动:当启动应用时,后台没有该程序的进程,此时启动的话系统会分 ...
- Android Studio 第一次启动配置
第一次启动AS前,为了避免重新下载新版本的SDK 操作如下: AS启动前,请先将bin目录的idea.properties文件中增加一行:disable.android.first.run=true ...
- Android Studio第一次启动失败的解决办法
Android Studio Android 开发环境 由于GFW的问题,安装后第一次启动会在显示Fetching android sdk component information对话框后,提示错误 ...
- freshStartTail 第一次启动时 抛弃旧的日志
freshStartTail [on/off] (requires v8.18.0+) Default: off This is used to tell rsyslog to seek to the ...
随机推荐
- Leetcode 题目整理-8 Count and Say
38. Count and Say The count-and-say sequence is the sequence of integers beginning as follows: 1, 11 ...
- Idea-LifecycleException when deploying
案例 今天第一次用idea构建项目,出现了如下问题: FAIL - Application at context path /myWebApp could not be started FAIL - ...
- Vue使用better-scroll左右菜单联动
说明 最近想做一个vue商城小项目,练习一下vue的语法,刚刚好碰到了需要左右菜单实现联动,因此就接触了 better-scroll. github地址 中文文档. 代码 页面结构以及数据 //页面结 ...
- tmobst2
(单选题)与下面代码效果相同的HQL 语句是( ). Criteria criteria = session.createCriteria(User.class); criteria.add(Rest ...
- edltplus使用正则表达式替换多余空行
24-7 <font style="font-weight:bold;">24-7</font><div class="tab_conten ...
- Sqli-Labs 闯关 less 42-49
Less 42 这一关一进去看着像前面的二次注入.发现也注入不了.. 我们观察代码发现这一关用的是堆叠注入. 登陆的这里可以看到login_password登陆的时候并没有使用mysqli_real_ ...
- 【限时免费】近1000G JAVA学习视频下载
2020的情人节是个极特殊的情人节,面对肆虐的疫情,我们无法出门,宅在家里,也无法阻止你作为一名优秀程序员的梦想. 或许没有鲜花.没有蛋糕…… 姜小白就为大家备好了一份大礼,将自己近几年整理收藏的全网 ...
- C# WinForm 使用SMS接口发送手机验证码+图形验证码+IP限制
https://blog.csdn.net/IT_xiao_guang_guang/article/details/104299983 前言 1.发送手机验证码用的是网建的SMS接口(http:/ ...
- Codeforces_814
A.b序列从大到小填a序列中的0,在判断. #include<bits/stdc++.h> using namespace std; ],b[]; int main() { ios::sy ...
- 为了控制Bean的加载我使出了这些杀手锏
故事一: 绝代有佳人,幽居在空谷 美女同学小张,在工作中遇到了烦心事.心情那是破凉破凉的,无法言喻. 故事背景是最近由于需求变动,小张在项目中加入了MQ的集成,刚开始还没什么问题,后面慢慢问题的显露出 ...