0% found this document useful (0 votes)
42 views3 pages

Bundle Data Type in Kotlin

Uploaded by

Hussain Nawaz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views3 pages

Bundle Data Type in Kotlin

Uploaded by

Hussain Nawaz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

===main activity===

package [Link]

import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]

class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {


[Link](savedInstanceState)
enableEdgeToEdge()
setContentView([Link].activity_main)

val b1 = findViewById<Button>([Link])
val et1 = findViewById<EditText>([Link])
val et2 = findViewById<EditText>([Link].editTextText2)
val etFirstName = findViewById<EditText>([Link])
val etLastName = findViewById<EditText>([Link])

[Link](findViewById([Link])) { v,
insets ->
val systemBars = [Link]([Link]())
[Link]([Link], [Link], [Link],
[Link])
insets
}

[Link] {
val n1 = [Link]().toInt()
val n2 = [Link]().toInt()
val sum = n1 + n2
val firstName = [Link]()
val lastName = [Link]()

val intent = Intent(applicationContext, SecondActivity::[Link])


val bundle = Bundle()
[Link]("number1", n1)
[Link]("number2", n2)
[Link]("sum", sum)
[Link]("firstName", firstName)
[Link]("lastName", lastName)
[Link](bundle)
startActivityForResult(intent, 100)
}
}

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?)


{
[Link](requestCode, resultCode, data)
if (resultCode == RESULT_OK) {
if (requestCode == 100) {
val thankYouMsg = data?.extras?.getString("msg").toString()
[Link](applicationContext, thankYouMsg,
Toast.LENGTH_LONG).show()
}
}
}
}

=====2nd activity===
package [Link]

import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]

class SecondActivity : AppCompatActivity() {


override fun onCreate(savedInstanceState: Bundle?) {
[Link](savedInstanceState)
enableEdgeToEdge()
setContentView([Link].activity_second)

val b1 = findViewById<Button>([Link].button2)
val tv1 = findViewById<TextView>([Link].textView2)
val et1 = findViewById<EditText>([Link].editTextText3)
val tvFirstName = findViewById<TextView>([Link])
val tvLastName = findViewById<TextView>([Link])

[Link](findViewById([Link])) { v,
insets ->
val systemBars = [Link]([Link]())
[Link]([Link], [Link], [Link],
[Link])
insets
}

val bundle = [Link]


val number1 = bundle?.getInt("number1", 0) ?: 0
val number2 = bundle?.getInt("number2", 0) ?: 0
val sum = bundle?.getInt("sum", 0) ?: 0
val firstName = bundle?.getString("firstName") ?: ""
val lastName = bundle?.getString("lastName") ?: ""

[Link] = "Sum: $sum"


[Link] = "First Name: $firstName"
[Link] = "Last Name: $lastName"

[Link] {
val thankYouMsg = [Link]()
val replyIntent = Intent()
val replyBundle = Bundle()
[Link]("msg", thankYouMsg)
[Link](replyBundle)
setResult(RESULT_OK, replyIntent) // successful flag
finish() // return
}
}
}

You might also like