I am trying to get the document that is stored in Firebase Cloud Firestore to my custom object(animal). I need to pass this object to another Activity. I used intent.putextra("class name", obj)
function but I can't reach the object that i created to get a document. Here is my code:
public void start(View view){
String id;
EditText animalIdEditText = findViewById(R.id.animalIDsearch);
String animalId = animalIdEditText.getText().toString();
FirebaseFirestore db = FirebaseFirestore.getInstance();
DocumentReference docRef = db.collection("Animals").document(animalId);
docRef.get().addOnSuccessListener(new OnSuccessListener<DocumentSnapshot>() {
@Override
public void onSuccess(DocumentSnapshot documentSnapshot) {
Animal animal = documentSnapshot.toObject(Animal.class); // this is where I create animal object. It doesn't let me declare it above either.
}
});
Intent intent = new Intent(this, searchActivity.class);
intent.putExtra("Animal",animal); // error in this line : animal can't be resolved
startActivity(intent);
}