2024年安卓最新Android-第四节02Activity(创建、跳转与传值),2024年最新字节跳动面试好难

最后

如果你看到了这里,觉得文章写得不错就给个赞呗?如果你觉得那里值得改进的,请给我留言。一定会认真查询,修正不足。谢谢。

最后针对Android程序员,我这边给大家整理了一些资料,包括不限于高级UI、性能优化、移动架构师、NDK、混合式开发(ReactNative+Weex)微信小程序、Flutter等全方面的Android进阶实践技术;希望能帮助到大家,也节省大家在网上搜索资料的时间来学习,也可以分享动态给身边好友一起学习!

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化学习资料的朋友,可以戳这里获取

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

activity1xml:

<?xml version="1.0" encoding="utf-8"?>

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android=“http://schemas.android.com/apk/res/android”

xmlns:app=“http://schemas.android.com/apk/res-auto”

xmlns:tools=“http://schemas.android.com/tools”

android:layout_width=“match_parent”

android:layout_height=“match_parent”

tools:context=“.MainActivity”>

<TextView

android:id=“@+id/textView”

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:text=“这是第一个页面”

android:textSize=“20dp”

app:layout_constraintBottom_toBottomOf=“parent”

app:layout_constraintLeft_toLeftOf=“parent”

app:layout_constraintRight_toRightOf=“parent”

app:layout_constraintTop_toTopOf=“parent” />

<Button

android:id=“@+id/button”

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_marginStart=“20dp”

android:layout_marginTop=“55dp”

android:text=“跳转”

app:layout_constraintStart_toStartOf=“@+id/textView”

app:layout_constraintTop_toBottomOf=“@+id/textView” />

<EditText

android:id=“@+id/editText”

android:layout_width=“169dp”

android:layout_height=“44dp”

android:layout_marginStart=“88dp”

android:layout_marginTop=“164dp”

android:layout_marginEnd=“88dp”

android:hint=“请输入”

android:inputType=“text”

app:layout_constraintEnd_toEndOf=“@+id/textView”

app:layout_constraintHorizontal_bias=“0.0”

app:layout_constraintStart_toStartOf=“parent”

app:layout_constraintTop_toTopOf=“parent” />

</androidx.constraintlayout.widget.ConstraintLayout>

activity2xml代码:

<?xml version="1.0" encoding="utf-8"?>

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android=“http://schemas.android.com/apk/res/android”

xmlns:app=“http://schemas.android.com/apk/res-auto”

xmlns:tools=“http://schemas.android.com/tools”

android:layout_width=“match_parent”

android:layout_height=“match_parent”

tools:context=“.MainActivity2”>

<TextView

android:id=“@+id/textView2”

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_marginStart=“87dp”

android:layout_marginTop=“57dp”

android:text=“这是第二个页面”

app:layout_constraintStart_toStartOf=“parent”

app:layout_constraintTop_toTopOf=“parent” />

<Button

android:id=“@+id/button2”

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_marginStart=“99dp”

android:layout_marginTop=“192dp”

android:text=“返回”

app:backgroundTint=“@color/teal_200”

app:layout_constraintStart_toStartOf=“parent”

app:layout_constraintTop_toTopOf=“parent” />

<TextView

android:id=“@+id/textView3”

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_marginStart=“121dp”

android:layout_marginTop=“101dp”

android:text=“TextView”

app:layout_constraintStart_toStartOf=“parent”

app:layout_constraintTop_toBottomOf=“@+id/button2” />

</androidx.constraintlayout.widget.ConstraintLayout>

3.运行结果:

在这里插入图片描述

传递对象数据

1.创建实体类实现Serializable接口:

在这里插入图片描述

2.activity1向activity2传递数据:

在这里插入图片描述

3.activity2接收数据:

在这里插入图片描述

4.运行结果:

在这里插入图片描述

核心代码:

activity2xml:

<?xml version="1.0" encoding="utf-8"?>

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android=“http://schemas.android.com/apk/res/android”

xmlns:app=“http://schemas.android.com/apk/res-auto”

xmlns:tools=“http://schemas.android.com/tools”

android:layout_width=“match_parent”

android:layout_height=“match_parent”

tools:context=“.MainActivity2”>

<TextView

android:id=“@+id/textView2”

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_marginStart=“87dp”

android:layout_marginTop=“57dp”

android:text=“这是第二个页面”

app:layout_constraintStart_toStartOf=“parent”

app:layout_constraintTop_toTopOf=“parent” />

<Button

android:id=“@+id/button2”

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_marginStart=“99dp”

android:layout_marginTop=“192dp”

android:text=“返回”

app:backgroundTint=“@color/teal_200”

app:layout_constraintStart_toStartOf=“parent”

app:layout_constraintTop_toTopOf=“parent” />

<TextView

android:id=“@+id/textView3”

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_marginStart=“121dp”

android:layout_marginTop=“101dp”

android:text=“TextView”

app:layout_constraintStart_toStartOf=“parent”

app:layout_constraintTop_toBottomOf=“@+id/button2” />

<TextView

android:id=“@+id/textView4”

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_marginTop=“12dp”

android:layout_marginEnd=“1dp”

android:text=“TextView”

app:layout_constraintEnd_toEndOf=“@+id/textView3”

app:layout_constraintTop_toBottomOf=“@+id/textView3” />

</androidx.constraintlayout.widget.ConstraintLayout>

activity1代码:

Button button=findViewById(R.id.button);

button.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

Phone phone=new Phone();

phone.name=“HUAWEIMate40”;

phone.price=6088;

Intent intent=new Intent(MainActivity.this,MainActivity2.class);

intent.putExtra(“key”,phone);

startActivity(intent);

}

});

activity2代码:

Phone phone= (Phone) getIntent().getSerializableExtra(“key”);//强制类型转换

TextView textView=findViewById(R.id.textView3);

TextView textView1=findViewById(R.id.textView4);

textView.setText(String.format(phone.name));

textView1.setText(String.format(String.valueOf(phone.price)));

六、数据回传

=====================================================================

1.activity1 注意和上面的代码区别

在这里插入图片描述

2.activity2页面回传

在这里插入图片描述

3.运行结果在这里插入图片描述

核心代码:

activity1xml:

<?xml version="1.0" encoding="utf-8"?>

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android=“http://schemas.android.com/apk/res/android”

xmlns:app=“http://schemas.android.com/apk/res-auto”

xmlns:tools=“http://schemas.android.com/tools”

android:layout_width=“match_parent”

android:layout_height=“match_parent”

tools:context=“.MainActivity”>

<TextView

android:id=“@+id/textView”

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:text=“这是第一个页面”

android:textSize=“20dp”

app:layout_constraintBottom_toBottomOf=“parent”

app:layout_constraintLeft_toLeftOf=“parent”

app:layout_constraintRight_toRightOf=“parent”

app:layout_constraintTop_toTopOf=“parent” />

<Button

android:id=“@+id/button”

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_marginStart=“20dp”

android:layout_marginTop=“55dp”

android:text=“跳转”

app:layout_constraintStart_toStartOf=“@+id/textView”

app:layout_constraintTop_toBottomOf=“@+id/textView” />

<TextView

android:id=“@+id/textView5”

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_marginTop=“54dp”

android:layout_marginEnd=“9dp”

android:text=“TextView”

android:inputType=“number”

app:layout_constraintEnd_toEndOf=“@+id/button”

app:layout_constraintTop_toBottomOf=“@+id/button” />

</androidx.constraintlayout.widget.ConstraintLayout>

activity2xml:

<?xml version="1.0" encoding="utf-8"?>

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android=“http://schemas.android.com/apk/res/android”

xmlns:app=“http://schemas.android.com/apk/res-auto”

xmlns:tools=“http://schemas.android.com/tools”

android:layout_width=“match_parent”

android:layout_height=“match_parent”

tools:context=“.MainActivity2”>

<TextView

android:id=“@+id/textView2”

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_marginStart=“87dp”

android:layout_marginTop=“57dp”

android:text=“这是第二个页面”

app:layout_constraintStart_toStartOf=“parent”

app:layout_constraintTop_toTopOf=“parent” />

<Button

android:id=“@+id/button2”

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_marginStart=“99dp”

android:layout_marginTop=“192dp”

android:text=“返回”

app:backgroundTint=“@color/teal_200”

app:layout_constraintStart_toStartOf=“parent”

app:layout_constraintTop_toTopOf=“parent” />

<EditText

android:id=“@+id/editText”

android:layout_width=“200dp”

android:layout_height=“wrap_content”

最后

题外话,我在一线互联网企业工作十余年里,指导过不少同行后辈。帮助很多人得到了学习和成长。

我意识到有很多经验和知识值得分享给大家,也可以通过我们的能力和经验解答大家在IT学习中的很多困惑,所以在工作繁忙的情况下还是坚持各种整理和分享。但苦于知识传播途径有限,很多程序员朋友无法获得正确的资料得到学习提升,故此将并将重要的Android进阶资料包括自定义view、性能优化、MVC与MVP与MVVM三大框架的区别、NDK技术、阿里面试题精编汇总、常见源码分析等学习资料。

【Android思维脑图(技能树)】

知识不体系?这里还有整理出来的Android进阶学习的思维脑图,给大家参考一个方向。

Android开发8年,阿里、百度一面惨被吊打!我是否应该转行了?

【Android进阶学习视频】、【全套Android面试秘籍】

希望我能够用我的力量帮助更多迷茫、困惑的朋友们,帮助大家在IT道路上学习和发展

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化学习资料的朋友,可以戳这里获取

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

知识值得分享给大家,也可以通过我们的能力和经验解答大家在IT学习中的很多困惑,所以在工作繁忙的情况下还是坚持各种整理和分享。但苦于知识传播途径有限,很多程序员朋友无法获得正确的资料得到学习提升,故此将并将重要的Android进阶资料包括自定义view、性能优化、MVC与MVP与MVVM三大框架的区别、NDK技术、阿里面试题精编汇总、常见源码分析等学习资料。

【Android思维脑图(技能树)】

知识不体系?这里还有整理出来的Android进阶学习的思维脑图,给大家参考一个方向。

[外链图片转存中…(img-TfMGotyU-1715804173464)]

【Android进阶学习视频】、【全套Android面试秘籍】

希望我能够用我的力量帮助更多迷茫、困惑的朋友们,帮助大家在IT道路上学习和发展

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化学习资料的朋友,可以戳这里获取

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值