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

测试

布局技巧


相关推荐
SHEN_ZIYUAN4 小时前
深度解析:从 AnimationHandler 原理看 Android 动画内存泄漏
android
冬奇Lab4 小时前
稳定性性能系列之十六——车机特定场景:黑卡死问题分析与排查实战
android·性能优化
座山雕~5 小时前
Springboot
android·spring boot·后端
香气袭人知骤暖6 小时前
SQL慢查询常见优化步骤
android·数据库·sql
丨康有为丨6 小时前
Android滑动冲突详解(场景+解决)
android
千里马学框架7 小时前
疑难ANR面试题:crash导致ANR深入剖析
android·智能手机·framework·perfetto·性能·anr·小米汽车
jerwey8 小时前
VSCode + Copilot下:配置并使用 DeepSeek
ide·vscode·copilot
石像鬼₧魂石10 小时前
安卓 WiFi 钓鱼渗透测试全流程教程(详细版)
android
奔跑吧 android10 小时前
【vscode】【Continue】【插件使用】
ide·vscode·编辑器
YIN_尹11 小时前
【MySQL】表的约束(上)
android·数据库·mysql