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

测试

布局技巧


相关推荐
新青年.26 分钟前
Android(Compose)使用 LibVLC 播放 RTSP 视频流
android
一见1 小时前
WorkBuddy安装Skill的方法
android·java·javascript
毛骗导演1 小时前
万字解析 OpenClaw 源码架构-跨平台应用之Android 应用
android·前端·架构
yatum_20141 小时前
VirtualBox 搭建 Hadoop-2.7.3 集群完整安装总结
java·ide·eclipse
happymaker06262 小时前
JDBC(MySQL)——DAY02
android·数据库·mysql
PenguinLetsGo2 小时前
代码段的消失:页表异常清零引发的 ILL_ILLOPC 溯源
android·linux
huangchen2 小时前
Compose 中 viewModel() 函数分析
android
Tobinary2 小时前
Android系统启动
android
AI+程序员在路上2 小时前
在pyCharm 中命令打包生成exe文件方法
ide·python·pycharm
我又来搬代码了3 小时前
【Android】基于GDAL库实现SHP文件读写
android