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

测试

布局技巧


相关推荐
阿pin1 天前
Android随笔-kotlin withContext
android·kotlin·withcontext
树码小子1 天前
开启 IDEA 中的断言功能
android·java·intellij-idea
Kslient1 天前
HeaderBehavior
android
Android-Flutter1 天前
android 动画详解
android·kotlin
小孔龙1 天前
GraphicBuffer 跨进程共享
android
树码小子1 天前
Pycharm解释器配置问题解决
ide·python·pycharm
行业研究员1 天前
Android内置GPS与腾讯地图定位技术对比分析
android·android定位·腾讯地图定位
Android-Flutter2 天前
android WMS 详解(二)
android·kotlin
游戏开发爱好者82 天前
App Store 上传 IPA 自动化,.p8 密钥认证与 CI/CD 接入实战
android·运维·ci/cd·小程序·uni-app·自动化·iphone
FlyWIHTSKY2 天前
idea中集成claude功能
java·ide·人工智能·intellij-idea·cloudera