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

测试

布局技巧


相关推荐
HealthScience2 小时前
【Bib 2026】基因最新综述(有什么任务、benchmark、代表性模型)
android·开发语言·kotlin
夏沫琅琊3 小时前
Android拨打电话技术文档
android·kotlin
a2591748032-随心所记3 小时前
android studio gradle快速编译配置
android·android studio
一块小土坷垃3 小时前
# 《电影猎手》观影伴侣:一款支持iOS/安卓/电视盒子的全平台影视工具“电影猎手”(附自用评价)
android·ios·电视盒子
L-影4 小时前
vscode安装SQLAlchemy步骤
ide·vscode·编辑器
敲代码的鱼哇5 小时前
发送短信/拨打电话/获取联系人能力 UTS 插件(cz-sms)
android·前端·ios·uni-app·安卓·harmonyos·鸿蒙
西门大盗6 小时前
pycharm自动进行python 测试(python test)
ide·python·pycharm
用户5052372099156 小时前
Android 13/14 通知权限与前台服务适配指南
android
用户5052372099156 小时前
Android 12 适配指南:SplashScreen API 与 PendingIntent 变更
android
用户5052372099156 小时前
一张表看懂 Android 8-15 所有适配要点
android