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

测试

布局技巧


相关推荐
成都大菠萝6 小时前
Android Car CarProperty 车辆信号链路
android
敲代码的鱼7 小时前
PDF 预览与签名批注写回 支持安卓 iOS 鸿蒙 UTS插件
android·前端·ios
时光足迹8 小时前
uni-app 视频通话实战:康复师与患者视频问诊的 6 个致命 Bug 与解决方案
android·ios·uni-app
Coffeeee12 小时前
闲聊几句,Android老哥们,你们多久没做技改需求了
android·程序员·代码规范
萝卜er13 小时前
Fragment 生命周期与状态恢复-《Android深水区(四)》
android
萝卜er13 小时前
Intent 显式、隐式与 PendingIntent-《Android深水区(五)》
android
Kapaseker15 小时前
一文吃透 Kotlin 集合操作符
android·kotlin
三少爷的鞋17 小时前
Main-safe:现代Android 架构真正的分水岭
android
沐怡旸1 天前
深入解析 Android Performance Analyzer (APA) 底层架构与技术原理
android
李斯维1 天前
从历史的角度看 Android 软件架构
android·架构·android jetpack