------------------------------------------------------------------------------------
MainActivity.kt
------------------------------------------------------------------------------------
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
title = "메인 액티비티"
var btnNewActivity = findViewById<Button>(R.id.btnNewActivity)
btnNewActivity.setOnClickListener {
var edtNum1 = findViewById<EditText>(R.id.edtNum1)
var edtNum2 = findViewById<EditText>(R.id.edtNum2)
var intent = Intent(applicationContext, SecondActivity::class.java)
if (resultCode == Activity.RESULT_OK) {
var hap = data!!.getIntExtra("Hap", 0)
Toast.makeText(applicationContext, "합계 :$hap", Toast.LENGTH_SHORT).show()
}
}
}
------------------------------------------------------------------------------------
***** SecondActivity.kt **
-- New --> Kotlin Class/File
-- Name : SecondActivity
------------------------------------------------------------------------------------
class SecondActivity : AppCompatActivity() {
lateinit var reciveData1: String
lateinit var reciveData2: String
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_second)
title = "Second 액티비티"
var btnReturn = findViewById<Button>(R.id.btnReturn)
var textView = findViewById<TextView>(R.id.reciveData)
var inIntent = intent
reciveData1 = inIntent.getStringExtra("Num1").toString()
reciveData2 = inIntent.getStringExtra("Num2").toString()
textView.text=" Main Activity로 부터 받은 값은 $reciveData1 와 $reciveData2 입니다." +
"\n"+" 되돌아가기 버튼을 클릭하면, " +
"\n"+" 더하기 한 값을 Main Activity로 보냄니다."