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

测试

布局技巧


相关推荐
BoomHe13 小时前
Android AOSP13 原生 Launcher3 壁纸获取方式
android
Digitally14 小时前
如何将联系人从 Android 转移到 Android
android
Freak嵌入式15 小时前
LVGL基础知识和概念:视觉样式与资源系统
ide·驱动开发·嵌入式·lvgl·micropython·upypi
李小枫15 小时前
webflux接收application/x-www-form-urlencoded参数
android·java·开发语言
爱丽_15 小时前
MySQL `EXPLAIN`:看懂执行计划、判断索引是否生效与排错套路
android·数据库·mysql
NPE~15 小时前
[App逆向]环境搭建下篇 — — 逆向源码+hook实战
android·javascript·python·教程·逆向·hook·逆向分析
追风201915 小时前
PowerShell 7 解决 Codex 中文乱码:完整经验总结(VsCode 背景)
ide·vscode·编辑器
yewq-cn17 小时前
AOSP 下载
android
cch891817 小时前
Laravel vs ThinkPHP:PHP框架终极对决
android·php·laravel
米码收割机17 小时前
【Android】基于安卓app的汽车租赁管理系统(源码+部署方式+论文)[独一无二]
android·汽车