【Android Studio】Intent实现两个Activity页面的跳转(基于Empty View Activity)

文章目录

为什么使用EmptyViewActivity而不是EmptyActivity

因为笔者使用的AndroidStudio版本比较新,经过测试从水母版开始EmptyActivity就不再支持选择JAVA语言,本次实验使用的AndroidStudio版本如下图所示:

准备工作:创建EmptyViewActivity项目


最原始项目结构如下:

准备工作:新建SecondActivity


如下图所示,会多出两个文件:一个是Activity文件,另一个是布局文件

调试一下原始项目


添加button

给MainActivity设置button



写跳转方法

java 复制代码
    public void toSecond(View view) {
        Intent intent =new Intent();
        intent.setClass(this,SecondActivity.class);
        startActivity(intent);
    }

测试

布局技巧


相关推荐
海市公约4 小时前
HTML网页开发从入门到精通:从标签到表单的完整指南
前端·ide·vscode·程序人生·架构·前端框架·html
2501_937193144 小时前
技术加持!PLB-TV:HDR10+UDP 传输
android·源码·源代码管理·机顶盒
霸王大陆6 小时前
《零基础学 PHP:从入门到实战》模块十:从应用到精通——掌握PHP进阶技术与现代化开发实战-2
android·开发语言·php
低调小一10 小时前
在 Android 上获取视频流逐帧时间戳并与 GPS/IMU 对齐(CameraX 实践)
android
Android_Trot10 小时前
Flutter android 多渠道配置,多包名、icon、等配置。
android·flutter
zhangphil11 小时前
Android性能:trace上的锁竞争monitor contention with owner at
android
砖厂小工12 小时前
Now In Android 精讲 9 - Benchmark 与 Baseline Profile
android
愤怒的代码12 小时前
深入解析 SystemUI 依赖注入:Dagger2 与 Hilt 核心机制重温
android·dagger
從南走到北14 小时前
JAVA海外短剧国际版源码支持H5+Android+IOS
android·java·ios