class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) val number1 = idOf_editTextnumber1.text.toString() val number2 = idOf_editTextnumber2.text.toString() idOf_OpeninActvity2.setOnClickListener { val newIntentOfOpening = Intent(this, SecondActivity::class.java) newIntentOfOpening.putExtra("number1", number1) newIntentOfOpening.putExtra("number2", number2) startActivityForResult(newIntentOfOpening, 1) } } override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { super.onActivityResult(requestCode, resultCode, data) if (requestCode == 1){ if (resultCode == Activity.RESULT_OK){ val intent3 = Intent() val result = intent3.extras?.getString("result") idOf_textViewOfResult.text = result } if (resultCode == Activity.RESULT_CANCELED){ idOf_textViewOfResult.text = "Nothing selected" } } } The Second Activity:
override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_second) val intentNew = Intent() val number1 = intentNew.getIntExtra("number1",0) val number2 = intentNew.getIntExtra("number2",0) idOf_ShowingTwoNumbers.text = "Numbers: $number1, $number2" idOf_Adding.setOnClickListener { val result: Int = number1 + number2 val intent2 = Intent() intent2.putExtra("result", result) setResult(Activity.RESULT_OK, intent2) finish() }
val number1 = intentNew.extras!!.getString("number1") val number2 = intentNew.extras!!.getString("number2")
val number1 = intentNew.getIntExtra("number1",0) val number2 = intentNew.getIntExtra("number2",0)
Intent()
val intentNew = Intent()
Intent
val intentNew = new Intent()
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)