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

测试

布局技巧


相关推荐
有梦想的鱼13 小时前
vscode letax编译中英文论文(傻瓜式、一分钟)
ide·vscode·编辑器
qq_2147826114 小时前
GWalkR,部分替代Tableau!
ide·python·jupyter
似霰14 小时前
传统 Hal 开发笔记6----App 访问硬件服务
android·framework·hal
爱装代码的小瓶子14 小时前
【c++知识铺子】封装map和set(详细版)
android·java·c++
私人珍藏库15 小时前
AutoGLM无需豆包手机,让AI自动帮你点外卖-刷视频
android·ai·智能手机·工具·软件·辅助·autoglm
孤舟簔笠翁15 小时前
【Android驱动14】Android系统Crash工具使用方法和分析
android
帅得不敢出门16 小时前
MTK Android11 APP调用OTA升级
android·java·开发语言·framework
2501_9159090616 小时前
苹果应用加密方案的一种方法,在没有源码的前提下,如何处理 IPA 的安全问题
android·安全·ios·小程序·uni-app·iphone·webview
用户20187928316717 小时前
Android App 换肤原理:用 "装修小房子" 故事浅谈
android