Вы можете startActivityForResult
, и это даст вам результат в onActivityResult
.
Activity1
Intent(this, Activity2::class.java).also {
startActivityForResult(it,101)
}
fun function1(){
//your function code here
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if(requestCode==101 && resultCode==Activity.RESULT_OK){
// it will print key value Activity2 : value
Log.e("key value Activity2", data?.extras.getString("key"))
function1()
}
}
Activty2
override fun onDestroy(){
super.onDestroy()
val returnIntent = Intent()
returnIntent.putExtra("key", "value")
setResult(Activity.RESULT_OK, returnIntent)
finish()
}