Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

295
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda