Android背后的意图系统的基本原理 [英] The rationale behind Android intent system

查看:189
本文介绍了Android背后的意图系统的基本原理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找了一个这样的解释,也没有找到。

I've looked for an explanation for this and couldn't find one.

有人问我在面试的Andr​​oid为什么不允许通过的意图进行任何类型的。

I was asked in a job interview why Android doesn't allow to pass any type through an intent.

我很清楚的可能性 - 序列化,实施Parcelable界面,捆绑等

I'm well aware of the possibilities - Serialization, implementing "Parcelable" interface, bundle etc.

我想了解否认自定义类型/与意向对象的传球决定背后的理由。我被带到明白这是出于安全原因,但我觉得这些理由。

I want to understand the rationale behind the decision to deny the passing of custom types/objects with an intent. I was led to understand that it was for security reasons, but I find these reasons.

推荐答案

第一个原因很简单,因为意图的接收器几乎总是在不同的进程,这意味着不同的JVM。 由于流程和应用程序沙箱(这意味着他们不能看到对方的内存),您需要通过串行化(最常用parcelables的android系统),发送对象的描述,而不是发送对象实例(即:一个指针它在哪里的存储器)。

The first reason is simply because the receiver of the intent will almost always be in a different process, which means a different jvm. Because process and applications are sandbox (meaning they are not allowed to see each other's memory), you need to send a description of the object through serialization (most usually parcelables in android), rather than sending the object instance (ie: a pointer to the memory where it is).

还有一个原因,因为Kuffs说,就是意图可以生存,你要发送(特别是待定意向)对象的生命周期。

Another reason, as Kuffs said, is that intent can survive the lifespan of the object you want to send (especially with pending intents).

这篇关于Android背后的意图系统的基本原理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆