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

测试

布局技巧


相关推荐
赏金术士7 小时前
Kotlin ViewModel
android·kotlin
vistaup8 小时前
kotlin 二维码实现高斯模糊
android·kotlin
愈努力俞幸运9 小时前
function calling与mcp
android·数据库·redis
阿巴斯甜9 小时前
LeakCanary
android
阿巴斯甜10 小时前
compose
android
阿巴斯甜10 小时前
Glide
android
-SOLO-10 小时前
使用Perfetto debug trace查看超时slice
android
阿巴斯甜10 小时前
Retrofit
android
阿巴斯甜10 小时前
OkHttp
android
阿巴斯甜11 小时前
Flow
android