-6

So I tried the intent method but I always get a red underline under the "putExtra"

here is the code I tried:

next.setOnClickListener {
  var i=Intent(this,Screen6::class.java)
  i.putExtra("ID", id)
}

How can I do that?

EDIT: the id needed the function to.toString() but now I need to get it from the other activity how is that possible

1 Answers1

1

You can simply use the intents to send data and parameters from one activity to another activity in kotlin

val intent = Intent(this@OneActivity,TwoActivity::class.java);
intent.putExtra("username", userName)
startActivity(intent);

Where "username" will be key and userName will be actual data you will pass.

Pawan Soni
  • 860
  • 8
  • 19
wise4rmgod
  • 33
  • 1
  • 6
  • how to receive it in the other activity ? – Mohammed Ayman Atieh Jun 23 '20 at 12:53
  • 1
    In the other activity, you use the below code Fragment ` val ty = activity?.intent ty?.getStringExtra("username")` for Activity ` val ty = intent ty?.getStringExtra("username")` from my code am passing a String value that's why I used double "" and also received it with the getString method, you can also work with other data Type – wise4rmgod Jun 23 '20 at 13:17
  • 1
    you can also check out this link for more clarification (https://devofandroid.blogspot.com/2018/03/pass-data-between-activities-using.html) – wise4rmgod Jun 23 '20 at 13:27