【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);
    }

测试

布局技巧


相关推荐
小孔龙32 分钟前
VSync 与同步屏障:doFrame() 的优先调度
android·性能优化
kfzjw00844 分钟前
Android 的一帧完整渲染流程:从 VSYNC 到 Screen 的全链路解密
android
wWYy.2 小时前
Mysql:覆盖索引
android·数据库·mysql
Kapaseker2 小时前
如果我要从 List 中获取一段元素
android·kotlin
三少爷的鞋2 小时前
一次朋友圈发布流程,理解 Kotlin 协程为什么重新定义异步代码组织方式
android
FungLeo2 小时前
Flutter/Android Release 包连不上网?AndroidManifest INTERNET 权限排查实录
android·flutter
wWYy.4 小时前
Mysql:一行数据是怎么存储的?
android·数据库·mysql
漏刻有时12 小时前
PHP GeoJSON转PNG地图渲染程序开发笔记、源码解读、问题复盘与整改方案
android·笔记·php
-SOLO-13 小时前
解决VMware 显示比例被重置的问题
android
alexhilton14 小时前
探究Android Views、Flutter和Compose如何渲染你的UI
android·kotlin·android jetpack