0

I've been working on a Database with Firestore. The DB itself is working, but when I try to get the values from a harshMap I get a null value, eventhough I can see that the DB shows (on the page) the parameter I'm trying to get.

So my question is the next one: Is there a proper way to get a value from a harshMap in another activity?

There are some comments on the code, please take a look at them.

setup() on Activity "A"

private fun setup(){
           crearCuentaButton.setOnClickListener{
            if (inputEmail.text.isNotEmpty() && inputContraseña.text.isNotEmpty()){
                val db = FirebaseFirestore.getInstance()
                val userData = hashMapOf(
                    "username" to inputUsername.text.toString(),
                    "email" to inputEmail.text.toString()
                )
                db.collection("users")
                    .add(userData)
                FirebaseAuth.getInstance().createUserWithEmailAndPassword(inputEmail.text.toString(), inputContraseña.text.toString()) .addOnCompleteListener {
                    if(it.isSuccessful){
                        showAuth(it.result?.user?.email ?: "", ProviderType.Email)
                    }
                    else{
                        showError()
                    }
                }
                Intent(this, HomeActivity::class.java).also {
                    val userName = userData["username"]
                    println(userName)
                    it.putExtra("dataBaseUsernameValue", userName) //<------ this is the value I'm trying to get, the println shows the variable perfectly, but when passing it through, it doesn't.
                    
                }
            }
        }
}

onCreate on Activity "B"

class HomeActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_home)
    homeBanner()
    val username = intent.getStringExtra("dataBaseUsernameValue")

    println(username) //<----------------- here I get the "null"
}
  • Does this answer your question https://stackoverflow.com/questions/7578236/how-to-send-hashmap-value-to-another-activity-using-an-intent – Ananiya Jemberu May 21 '21 at 02:18
  • I fixed it! Sadly, I didn't use your link, I realised I didn't need to use that map because I could get the data I was needing from another place! Thank you for you help though! – Juan Sanchez May 22 '21 at 04:08

0 Answers0