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

测试

布局技巧


相关推荐
开维游戏引擎8 小时前
AI自动生成游戏时,deepseek和mimo对比
android·游戏·语言模型·游戏引擎·ai编程
OsDepK9 小时前
移动编程OSMDE随时命令行进行Git
ide·git
色空大师14 小时前
【debug调试详解-idea】
java·ide·intellij-idea·调试·远程调试
BreezeDove15 小时前
【Android】AS项目自动连接mumu模拟器配置
android
Tiger Z17 小时前
Positron 教程7 --- 工作区
ide·编程·positron
木囧17 小时前
PyCharm手动创建虚拟环境
ide·python·pycharm
乐世东方客17 小时前
备份脚本记录(binlog文件+mysql+mongo)
android·数据库·mysql
私人珍藏库18 小时前
[Android] 视频下载鸟 v20.02 会员
android·人工智能·智能手机·app·工具·多功能
zh_xuan18 小时前
tv浏览网页工具
android·tv浏览网页
爱就是恒久忍耐19 小时前
VSCode里clangd如何配置跳转
ide·vscode·编辑器