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

测试

布局技巧


相关推荐
2401_8582861112 小时前
VSCODE远程链接错误: 无法建立链接,过程试图写入的管道不存在的解决方法
ide·vscode·编辑器
wxson728214 小时前
【Android视频监控系统技术总结】
android·音视频
一朵好运莲14 小时前
Turbo Console Log插件VSCode更改log快捷键教程
ide·vscode·编辑器
hunterandroid15 小时前
[Android 从零到一] LiveData 粘性事件与单次消费:从重复触发到可靠事件总线
android
hunterandroid16 小时前
[Android 从零到一] Android 事件分发机制:从 ACTION_DOWN 到 View 事件消费链路
android
阿巴斯甜16 小时前
adb‑shell 全套命令实操总结
android
奔跑的架构师17 小时前
[A-49]ARMv9/v8-PSCI接口规范与工作流程简介
android·linux·arm开发·arm
AFinalStone17 小时前
Android 7系统国际化(七)Resources 与 AssetManager 源码剖析
android·国际化·local
Android-Flutter18 小时前
Android 内存泄漏详解
android·kotlin