Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

294
Views
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

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
over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

in HomeActivity are initializing the intent like

 getintent = Intent()

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

over 4 years ago · Santiago Trujillo Report

0

Please try this in your LoginScreen.kt:

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

and in your HomeActivity:

val string = intent!!.getStringExtra("intent")

The error is that you are instantiating a new Intent object.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!