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

测试

布局技巧


相关推荐
Android-Flutter7 小时前
Android的http和https知识点
android·http·https
Kapaseker8 小时前
Sequence 一定比 List 快?等等,我们先从基础讲起
android·kotlin
AI刀刀8 小时前
deepseek 内容粘贴后符号丢失怎么办?AI 导出鸭实测解决排版乱码问题
android·人工智能·excel·ai导出鸭
东方佑8 小时前
Per-Group 混合精度量化:将 14B 视频生成模型压缩至 11 GB
android
三少爷的鞋8 小时前
Android 面试系列 : 协程为何比线程高效
android
2501_932750269 小时前
Android 数据持久化解析
android·java
石山代码20 小时前
KMP全栈开发:从Android到AI Agent的技术演进与实践
android·人工智能
怣疯knight1 天前
kotlin安卓应用打包编译卡死的可能原因
android·kotlin
plainGeekDev1 天前
NullPointerException → Kotlin 空安全
android·java·kotlin
2501_916008891 天前
苹果上架工具怎么选 不用 Mac 上架 App Store 的几种方案
android·macos·ios·小程序·uni-app·iphone·webview