
/**
* 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));
}
"My question is how to use Bundle's getSerializable method to retrieve collection objects."
It's preferable to use Parcelable for Android rather than Serializable.
Hence, if you implement Parcelable for your TreeCatalogue class (easiest way is to use Parcelize)
Then you can use:
bundle.putParcelableArrayList("data", treeCatalogue)
When you create the bundle and:
val treeCatalogue = bundle.getParcelableArrayList<TreeCatalogue>("data")
When you restore it.
You can also use BundleCompat to get rid of the deprecation warning:
val treeCatalogue = BundleCompat.getParcelableArrayList(bundle, "data", TreeCatalogue::class.java)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With