I am working on an android project and I've been trying to use Firebase Firestore collections. Everything seems fine up until the second activity retrieving the intent with the parsed list of watches.
public class MainActivity extends AppCompatActivity {
private FirebaseFirestore db = FirebaseFirestore.getInstance();
private CollectionReference watchesRef = db.collection("watches");
private List<Watch> watches = new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
watchesRef.get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()) {
for (QueryDocumentSnapshot document : task.getResult()) {
Watch watch = document.toObject(Watch.class);
watches.add(watch);
}
Intent intent = new Intent(MainActivity.this, WatchesActivity.class);
intent.putParcelableArrayListExtra("watches", (ArrayList<Watch>) watches);
startActivity(intent);
} else {
Log.d("MainActivity", "Error getting documents: ", task.getException());
}
}
});
Say I wanted to print out each watch upon retrieval from firstore, it works just fine. When debugging, I can see the list getting filled with the watches. Debugging goes through to the next activity:
Intent intent = getIntent();
if (intent.hasExtra("watches")) {
watches = intent.getParcelableArrayListExtra("watches");
}
Right up until watches = intent.getParcelableArrayListExtra("watches");
I can see the data just fine, then I get this error java.lang.RuntimeException: Parcel android.os.Parcel@f983085: Unmarshalling unknown type code 7536745 at offset 316
KEEP IN MIND: When I clear the list then add static data, it works just fine.