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

测试

布局技巧


相关推荐
范特西林14 分钟前
代码的生成:AIDL 编译器与 Parcel 的序列化艺术
android
范特西林14 分钟前
深入内核:Binder 驱动的内存管理与事务调度
android
范特西林1 小时前
解剖麻雀:Binder 通信的整体架构全景图
android
范特西林1 小时前
破冰之旅:为什么 Android 选择了 Binder?
android
奔跑中的蜗牛6662 小时前
一次播放器架构升级:Android 直播间 ANR 下降 60%
android
测试工坊5 小时前
Android 视频播放卡顿检测——帧率之外的第二战场
android
Kapaseker6 小时前
一杯美式深入理解 data class
android·kotlin
鹏多多6 小时前
Flutter使用screenshot进行截屏和截长图以及分享保存的全流程指南
android·前端·flutter
Carson带你学Android6 小时前
OpenClaw移动端要来了?Android官宣AI原生支持App Functions
android
黄林晴6 小时前
Android 删了 XML 预览,现在你必须学 Compose 了
android