Problems receiving data from another Activity Android Kotlin, Intent must not be null

Asked

Viewed 80 times

0

Hello,

I am trying to pass the data I receive from a call to the API, and send this data to the next Activity, however I am receiving that Intent is null, as code below.

I have tried changing the context of Intent to applicationContext(), tried using the IDE’s Clean Project, and as Log shows, Intent is not null within the first Activity

Main Activity (first Activity)

val call= endpoint2.mePage()

    call.enqueue(object : Callback<ResponseBody>{
        override fun onResponse(call: Call<ResponseBody>, response: Response<ResponseBody>) {
            if (response.code() == 200) {
                Toast.makeText(baseContext, "Fazendo LoginActivity", Toast.LENGTH_SHORT).show()
                val meUser = response.body()!!.string()
                Log.e("Token Gerado", meUser)
                //{"email":"[email protected]","name":"José"}
                var intent= Intent(this@MainActivity,LoginActivity::class.java)
                intent.putExtra("dados",meUser)
                startActivity(intent)
                Log.e("INTENT", meUser)
                Log.e("INTENT2", intent.toString())
                Log.e("INTENT3", intent.getStringExtra("dados"))

        }else {
                var res = response.code().toString()
                Toast.makeText(baseContext, res, Toast.LENGTH_SHORT).show()
                Toast.makeText(baseContext, token, Toast.LENGTH_SHORT).show()
                Log.e("Token", token)
                Log.e("Response", res)
            }
        }

Logcat log And then to the second Activity below:

Loginactivity

var dadosUsuario = intent.extras.get("dados") as String?
var nome = dadosUsuario?.substringAfter("name\":")
    ?.replace("\"","")
    ?.replace("}","")
  • You tried to use only intent.getStringExtra in the second Activity?

  • I tried to use, but gave the same error the Intent comes as Null. I even tried to use: Startactivityonresult:

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.