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

测试

布局技巧


相关推荐
星空13 小时前
vscode开发环境配置
ide·vscode·编辑器
Ln5x9qZC213 小时前
Laravel AI SDK 正式发布
android·人工智能·laravel
huwuhang14 小时前
跨平台电子书阅读器 | Readest最新版 安卓版+PC版全平台
android·前端·javascript
Zww089114 小时前
idea配置注释模板
java·ide·intellij-idea
IOFsmLtzR14 小时前
Visual Studio 中的 Agent:内置 Agent 和自定义 Agent
ide·visual studio
Gse0a362g15 小时前
推荐 PHP 属性(Attributes) 简洁读取 API 扩展包
android·开发语言·php
十六年开源服务商15 小时前
WordPress服务器响应时间优化终极指南2026
android·运维·服务器
深挖派15 小时前
PyCharm 2026.1 全版本安装配置与全功能环境搭建 (保姆级图文教程)
ide·python·pycharm
jwn99915 小时前
PHP vs Go:后端开发选谁更胜一筹?
android
不明觉厉二十年15 小时前
pytest+pywinauto+pycharm制作mobaxterm 字符串快捷发送器 Demo
ide·pycharm·pytest