I want to open a new activity (from fragment) and pass an object of type QueryDocumentSnapshot
with Intent
. I'm familiar with the putExtra
method but it does not accept QueryDocumentSnapshot
. I saw this topic, and it said "If your Object Class implements Parcelable and Serializable then you can just cast". How do I know if QueryDocumentSnapshot
can be casted? If it's not possible, what would be the way to do it (I can't implements Parcelable
and Serializable
because QueryDocumentSnapshot
is not my class).
Asked
Active
Viewed 208 times
0

abuka123
- 441
- 3
- 12
1 Answers
1
From a quick scan of the documentation and the code it doesn't seem like QueryDocumentSnapshot
or DocumentSnapshot
are parcelable.
That means you'll have to store the data that you want to transport to another activity and that is parcelable into the extra. Typically this would be the snapshot's data and its document ID.

Frank van Puffelen
- 565,676
- 79
- 828
- 807
-
So I have to create a new class that implements `Parcelable`, pass the `QueryDocumentSnapshot` to the constructor, save it as a field, override the methods and that it? – abuka123 Jun 12 '20 at 12:57
-
That's one way to do it indeed. You could also just put the ID and data separately into the extra, for example by serializing the data to a JSON string, as strings are already parcelable. – Frank van Puffelen Jun 12 '20 at 15:28