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

测试

布局技巧


相关推荐
AllBlue几秒前
安卓调用unity中的方法
android·unity·游戏引擎
帮帮志8 分钟前
Jupyter使用的快捷键大全
ide·python·jupyter
qq_463944869 分钟前
Jupyter中输入标题的方法
ide·python·jupyter
zhimingwen27 分钟前
通过ADB获取Android应用的SHA1签名
android·adb
2501_9160074730 分钟前
深入理解 iOS 文件管理体系,从沙盒结构到多工具协同的工程化文件管理实践
android·ios·小程序·https·uni-app·iphone·webview
00后程序员张31 分钟前
iOS 性能检测工具深度解析 多工具协同下的全维度性能检测体系建设
android·ios·小程序·https·uni-app·iphone·webview
Xiaok101844 分钟前
VSCode 报错 “No module named ‘torch‘“
ide·vscode·编辑器
Kapaseker1 小时前
不卖课,纯干货!Android分层你知多少?
android·kotlin
橙子味de巧克力4491 小时前
【DataGrip】JetBrains 专业数据库 IDE!全流程管理 + 永久补丁(详细安装指南)
ide·windows
前端小王呀1 小时前
自定义图表相关配置
android·前端·javascript