gpt4 book ai didi

java - Android Activity 之间传递 protobuf

转载 作者:行者123 更新时间:2023-12-01 05:34:29 25 4
gpt4 key购买 nike

我有一个 ListView 来查看我的 protobuf 对象的列表。当用户单击 ListView 中的某个项目时,我想显示该对象的详细信息。目前,我正在将其作为一项单独的 Activity 来实现。在开始 Activity 之前,我需要传入对象数据。

我应该序列化我的 protobuf 对象并将其传递到子 Activity 中吗?子 Activity 必须反序列化 protobuf 对象。

或者我应该为我的子 Activity 提供某种访问器来修改父 Activity 的私有(private)字段?

最佳答案

Should I serialize my protobuf object and pass it in the child activity? The child activity will have to deserialize the protobuf object.

是的,这就是要走的路,:) ...或者你可以使用 Parcelable 。另一种选择是 extend the Application class并让它存储 protobuf 数据。这些数据将在您的所有 Activity 中均可访问。

Or should I provide some kind of accessor for my child activity to modify private fields of the parent activity?

不,这是一个坏主意

关于java - Android Activity 之间传递 protobuf,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8395650/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com