enter image description here

/**
 * Returns the value associated with the given key, or {@code null} if:
 * <ul>
 *     <li>No mapping of the desired type exists for the given key.
 *     <li>A {@code null} value is explicitly associated with the key.
 *     <li>The object is not of type {@code clazz}.
 * </ul>
 *
 * @param key   a String, or null
 * @param clazz The expected class of the returned type
 * @return a Serializable value, or null
 */
@Nullable
public <T extends Serializable> T getSerializable(@Nullable String key,
        @NonNull Class<T> clazz) {
    return super.getSerializable(key, requireNonNull(clazz));
}

"我的问题是如何使用Bundle的getSerializable方法来检索集合对象."

推荐答案

最好是使用Parcelable为Android,而不是Serializable.

因此,如果您为TreeCatalogue类实现Parcelable(最简单的方法是使用Parcelize)

然后您可以使用用途:

bundle.putParcelableArrayList("data", treeCatalogue)

当你创建bundle和:

val treeCatalogue = bundle.getParcelableArrayList<TreeCatalogue>("data")

当你恢复它.

您也可以使用BundleCompat来删除弃用警告:

val treeCatalogue = BundleCompat.getParcelableArrayList(bundle, "data", TreeCatalogue::class.java)

Android相关问答推荐

房间打开创建回调java.nio.channels. OverlappingFilLockResponse

CameraX与jetpack组成屏幕逻辑

无法列出目录中的文件'

如何检测HitTest是否命中给定的网格对象?

在Android Studio中,如何在BuildSrc Dependenices Kotlin文件中指定时标记与旧版本的依赖关系

从片段导航回来

如何在使用 PointerInput 修改器时添加点击时的波纹效果

在 kotlin 上向适配器添加绑定视图功能

如何在卡片视图右侧添加箭头

Android 导航 - 定义参数

如何在jetpack compose中使可组合的屏幕zoom 到不同的手机(屏幕)尺寸?

列表更改时,RecyclerView 中的列表不会更新

Kotlin Multiplatform Mobile targetSdk 已弃用

任务 ':app:checkReleaseDuplicateClasses' 执行失败

compose 导航参数字符串包含花括号?

每次在 Jetpack Compose 中调用导航

我该怎么做文本计时器

如何在 Compose 中使用合并的单元格创建网格视图?

在 Kotlin 中打开新片段时如何对当前片段应用更改?

使 Compose LazyColumn 的最后一项填满屏幕的其余部分