Bundle如何运作?(How does Bundle works?)

编程入门 行业动态 更新时间:2024-10-25 10:24:18
Bundle如何运作?(How does Bundle works?)

我不是问我该如何使用它,也不是它做什么,它是如何工作的 。 当我问到为什么他们只是放一个putExtra(String,Object)以便我可以传递一个对象时,问题就出现了。 显然他们只是没有忘记这样做,而不是Bundle工作的方式不是你能做到的。

PS: Serializable或Parcelable是你无法在你创建的每个类上实现的东西,因此它们不能替代putExtra(String,Object)

I'm not asking how do I use it nor what does it do, how does it works. The question came to me when I though why didn't they just put a putExtra(String,Object) so I can pass an object. Obviously they just didn't forgot to do it, rather than the way Bundle works isn't one you can just do that.

PS: Serializable or Parcelable is something you cannot implement on every class you create, so they are not a replacement for putExtra(String,Object)

最满意答案

显然他们只是没有忘记这样做

正确。

Bundle本身就是Parcelable,正如Doctoror Drive所说。 Parcelable背后的要点是能够将它放入一个Parcel ,并且Parcel后面的点是跨越进程边界传递数据。 您不能跨进程边界传递任意对象,就像您无法将任意对象写入文件而无法通过套接字流传输任意对象一样。

Obviously they just didn't forgot to do it

Correct.

A Bundle itself is Parcelable, as Doctoror Drive notes. The point behind a Parcelable is to be able to place it into a Parcel, and the point behind a Parcel is to pass the data across process boundaries. You cannot pass arbitrary objects across process boundaries, just as you cannot write arbitrary objects to a file and cannot stream arbitrary objects over a socket.

更多推荐

本文发布于:2023-08-04 13:57:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1416448.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Bundle   works

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!