0

I am trying to download an object from the firebase firestore database and send it to an other activity. Here is my code:

FirebaseFirestore.getInstance().collection(Constants.COLLECTION)
                        .document(getCurrentUid()!!)
                        .get()
                        .addOnSuccessListener {
                            snapshot ->
                            val user: User? = snapshot.toObject(User::class.java)
                            val intent = Intent(this, MainActivity::class.java)
                            intent.putExtra(Constants.USER_OBJECT, user)

                        }

but the problem is I am getting an error in intent.putExtra(Constants.USER_OBJECT, user).

My User class implements serializable

What is wrong here?

ADITYA DIXIT
  • 141
  • 1
  • 11

1 Answers1

-1

Is the Constant a String?

Otherwise you can try to cast your user to a Serializable and see if that fails, if it doesn't it should work.

So

   val user: User? = snapshot.toObject(User::class.java)
   val intent = Intent(this, MainActivity::class.java)
   intent.putExtra(Constants.USER_OBJECT, user as Serializable)

Make sure that user isn't null when passing it too. Maybe putExtra has been updated to only allow non-null values and your user might be null.

Merthan Erdem
  • 5,598
  • 2
  • 22
  • 29
  • My error was that user should be nullable. But I don't know how to make user object as nullable. Constants.USER_OBJECT is a string – ADITYA DIXIT May 16 '21 at 06:07