Open a New Activity on button click KOTLIN - Android studio

Published: 19 November 2022
on channel: Deccon Tech
625
5

How to Make a Button Open a New Activity - Android Studio Tutorial
android studio start activity with parameter
registerforactivityresult kotlin
fun loadAct(view: View) {
val intent = Intent(this,Activity2 :: class.java)
startActivity(intent)


}
fun loadActWv(view: View) {
val intent = Intent(this,Activity2 :: class.java)
intent.putExtra("type","update")
startActivity(intent)
activityLauncher.launch(intent)

}
private val activityLauncher = registerForActivityResult (
ActivityResultContracts.StartActivityForResult()){result:ActivityResult -
if(result.resultCode == 2 ){
Toast.makeText(this,"msg", Toast.LENGTH_SHORT).show()
}

}
class Activity2 : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_2)
val i = intent
val msg = i.getStringExtra("type")
Toast.makeText(this,msg,Toast.LENGTH_LONG).show()
}

fun btnClick(view: View) {
val intent = Intent()
intent.putExtra("itm_id", 1)
setResult(2, intent)
finish()

}


Watch video Open a New Activity on button click KOTLIN - Android studio online, duration hours minute second in high quality that is uploaded to the channel Deccon Tech 19 November 2022. Share the link to the video on social media so that your subscribers and friends will also watch this video. This video clip has been viewed 625 times and liked it 5 visitors.