Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

intent.getStringExtra() returns null

Im trying to send data class object to another activity with intent but it returned null so i tried sending simple string but it still returns null, i couldn’t find what is the problem. Here is my code

code in LoginScreen.kt

                val intentUser = Intent(this@LoginScreen,HomeActivity::class.java)
                val string = "intent"
                intentUser.putExtra("intent",string)
                startActivity(intentUser)
                finish()

and code in my HomeActivity

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

        val intentUser = Intent()
        var string = intentUser.getStringExtra("intent")
        Log.e("Intent: ",string.toString())

result

2022-02-23 14:25:09.139 11365-11365/com.scibilisim.d_forceandroid E/Intent:: null

>Solution :

in HomeActivity you are initializing intent as

intent = Intent()

This actually initializes the intent with a new intent object. That is not desired behavior, to achieve desired behavior use getIntent() instead of Intent().

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading