1
    fun kullaniciOlustur2(view: View){
        val intent = Intent(applicationContext,KullaniciOlustur2::class.java)

        intent.putExtra("input",makeUsername.text.toString())
        intent.putExtra("input2",makeUserphone.text.toString())
        startActivity(intent)
    }

Mainactivity2 starts here..before this, I was using

val intent = intent 
val received: String = intent.getStringExtra("input")   
makeUsername.text = received 

But this method doesn't work anymore. I tried using getIntent() but couldn't get anything

   val intent = getIntent()
Sagar
  • 23,903
  • 4
  • 62
  • 62
Ceridoglu
  • 75
  • 1
  • 2
  • 11

3 Answers3

3

Try this code

Activity 1

val intent = Intent(FirstActivity.this,SecondActivity::class.java) //not application context
intent.putExtra("input",makeUsername.text.toString())
intent.putExtra("input2",makeUserphone.text.toString())
startActivity(intent)

Activity 2

inside onCreate() method use

val stringOne = getIntent().getStringExtra("input")

Or more cleaner way is

val extras = getIntent().getExtras()
if (null != extras) {
    val value = extras.getString("input")
    //The key argument here must match that used in the other activity
}

and please check similar answers in Java, you may be able to get the Idea here already told in another answer.

I also Use Anko to remove this kind of boilerplate code

TapanHP
  • 5,969
  • 6
  • 37
  • 66
1

I recommend using Kotlin Anko, there are plenty of methods that will help you to remove this boilerplate code

check Anko Intents here

0

Use Below Code: The Code is same as Java .Just difference is kotlin do not have 1. No semicolon at the end. 2. to call another activity kotlin use ::

ex.KotlinActivity::class.java

startActivity(Intent(this, KotlinActivity::class.java).putExtra("DataTrasfer", ""))

To Get Value:

intent.getStringExtra("DataTrasfer")
Rohan Lodhi
  • 1,385
  • 9
  • 24