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

测试

布局技巧


相关推荐
冬奇Lab7 小时前
应用异常退出实战分析:一次"幽灵杀手"引发的车载系统故障排查
android·性能优化·debug
code bean9 小时前
Visual Studio 2026 离线安装包制作指南
ide·visual studio
Ehtan_Zheng11 小时前
如何简化状态和实体映射Kotlin接口,委托和协变泛型
android
你怎么知道我是队长12 小时前
VsCode插件推荐---Todo Tree
ide·vscode·编辑器
becatjd12 小时前
VScode的claude code插件报错command ‘claude-vscode.editor.openLast‘ not found
ide·vscode·编辑器·claude·anthropic·claude code
飘逸飘逸13 小时前
Autojs进阶前言
android·javascript
spencer_tseng13 小时前
Branding Printing System (Android Pad)
android·pad
BIBI204913 小时前
下载指定历史版本 VSCode 或 VSCode Insider
ide·vscode·编辑器
FrameNotWork13 小时前
多设备 Android Logcat 自动采集方案:基于 Docker + Shell 实现日志按天切割与自动清理
android·docker·容器