Parcelable 在何处/何时使用 describeContents()? [英] Parcelable where/when is describeContents() used?

查看:23
本文介绍了Parcelable 在何处/何时使用 describeContents()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道Parcelable的这个方法在哪里/何时被调用?

Does anyone know where/when this method of a Parcelable is called?

@Override
public int describeContents() {
    return 0;
}

它必须被覆盖.但是我应该考虑用它做一些有用的事情吗?

It has to be overriden. But should I consider doing something useful with it?

推荐答案

Parcelable 中定义了一个名为 CONTENTS_FILE_DESCRIPTOR 的常量,用于describeContents() 创建位掩码返回值.

There is a constant defined in Parcelable called CONTENTS_FILE_DESCRIPTOR which is meant to be used in describeContents() to create bitmask return value.

API ref中对CONTENTS_FILE_DESCRIPTOR的描述是:

与 describeContents() 一起使用的位掩码:每个位代表一种在编组时被认为具有潜在特殊意义的对象.

Bit masks for use with describeContents(): each bit represents a kind of object considered to have potential special significance when marshalled.

这真正意味着:如果您需要将 FileDescriptor 对象放入 Parcelable,您应该/必须指定 CONTENTS_FILE_DESCRIPTOR 作为 describeContents() 的返回值,即通过特殊对象"(在 describeContents() 的描述中)它们的真正意思是:FileDescriptor.

Which really means: If you need to put FileDescriptor object into Parcelable you should/must specify CONTENTS_FILE_DESCRIPTOR as return value of describeContents(), i.e. by "special object" (in describeContents()'s description) they really mean: FileDescriptor.

整个Parcelable 功能看起来还没有完成(阅读:设计很糟糕).文档中还有一件奇怪的事情:

This whole Parcelable functionality looks unfinished (read: has bad design). There is one other strange thing in the docs:

实现 Parcelable 接口的类还必须有一个名为 CREATOR 的静态字段,它是一个实现 Parcelable.Creator 接口的对象

Classes implementing the Parcelable interface must also have a static field called CREATOR, which is an object implementing the Parcelable.Creator interface

通过以人类可读形式定义的规则实现多重继承?:-)

Implementing multiple inheritance by rules defined in human readable form? :-)

似乎 C++ 程序员设计了 Parceable 并且在某些时候他意识到:哦,该死,Java 中没有多重继承...... :-)

It seems like C++ programmer designed Parceable and at some point he realized: Oh, damn, there is no multiple inheritance in Java... :-)

这篇关于Parcelable 在何处/何时使用 describeContents()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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