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

测试

布局技巧


相关推荐
时间的拾荒人36 分钟前
MySQL 视图详解
android·数据库·mysql
祉猷并茂,雯华若锦1 小时前
Appium 3.x安卓按键与通知栏操作全指南
android·appium
码农coding2 小时前
android 12 SurfaceFlinger开机启动分析
android
hunterandroid2 小时前
Paging 3 RemoteMediator 实战:构建离线优先的分页列表
android·前端
码农coding2 小时前
android12 开机启动PMS
android
Days20502 小时前
GPT-Image-2 国风美学人设生成提示词分享
android·gpt
浮江雾3 小时前
Flutter第十节-----Flutter布局与组件全解析
android·开发语言·前端·学习·flutter·入门
Jomurphys3 小时前
Compose 适配 - 自适应布局(窗口大小类 WindowSizeClasses、列表详情、辅助窗格)
android·compose
plainGeekDev4 小时前
synchronized → Coroutines
android·java·kotlin
sun0077005 小时前
gtest 行覆盖率、函数覆盖率、分支覆盖率 . 一般这3个要达到多少?算达标
android