Two activities connected with an intent with a string message.
[android-PittiHelloWorld.git] / app / src / main / java / com / example / pittihelloworld / MainActivity.kt
1 package com.example.pittihelloworld
2
3 import android.content.Intent
4 import androidx.appcompat.app.AppCompatActivity
5 import android.os.Bundle
6 import android.view.View
7 import android.widget.EditText
8
9 const val EXTRA_MESSAGE = "com.example.pittihelloworld.MESSAGE"
10
11 class MainActivity : AppCompatActivity() {
12     override fun onCreate(savedInstanceState: Bundle?) {
13         super.onCreate(savedInstanceState)
14         setContentView(R.layout.activity_main)
15     }
16
17     fun sendMessage(view: View) {
18         val editText = findViewById<EditText>(R.id.messageText)
19         val message = editText.text.toString()
20         val intent = Intent(this, DisplayMessageActivity::class.java).apply {
21             putExtra(EXTRA_MESSAGE, message)
22         }
23         startActivity(intent)
24     }
25 }