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

测试

布局技巧


相关推荐
2501_915918414 小时前
深入对比iOS开发中常用性能监控工具的底层原理与优缺点分析
android·ios·小程序·https·uni-app·iphone·webview
my_power5205 小时前
android中Activity生命周期函数的职责
android
Sirens.5 小时前
从参考 iCost 到做自己的 OneLedger:一个 Android 本地记账 App 的开发记录
android·kotlin·room·jetpack compose·记账 app
qq_448011165 小时前
C语言中的变量和函数的定义与声明
android·c语言·开发语言
码农coding9 小时前
android 12 中的VSYNC的请求
android
阿pin9 小时前
Android随笔-Activity
android·activity
YF02119 小时前
详解Android所有文件访问权限
android
时间的拾荒人10 小时前
MySQL C语言连接 - 从入门到实战
android·c语言·mysql
Meteors.11 小时前
Android性能优化:01. 指标体系 + 分析工具链
android
放学校门口见11 小时前
vscode部署stm32开发调试环境
ide·vscode·stm32