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

测试

布局技巧


相关推荐
木木子2229 分钟前
[特殊字符] 音乐播放器——状态驱动的多媒体控制
android·开发语言·华为·php·harmonyos
雨白1 小时前
C 语言基础:结构体、联合体与枚举
android
阿巴斯甜2 小时前
Android 代码混淆
android
球king4 小时前
CC GUI 插件:在 IDEA 中使用 CodeX
java·ide·intellij-idea
apihz4 小时前
台风实时与历史详情查询免费 API 接口完整教程
android·开发语言·tcp/ip·dubbo·台风·天气预报
浪客川5 小时前
AOSP源码隐藏状态栏
android·aosp
没有了遇见5 小时前
AI Agent 是什么?—— 一文理解 LLM、Memory、Skills、Tools、MCP、Workflow,Context
android·前端·程序员
御坂嘀喵6 小时前
Speed Tools:一套低侵入的 Android 插件化 + 动态换肤 + 字体切换框架
android·gitee
浮江雾6 小时前
Flutter第三节----Dart中的数据类型
android·开发语言·学习·flutter·入门·函数
不负信仰6 小时前
Visual Studio 三月更新 —— 打造专属自定义 Agent
ide·visual studio