
activity_main.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" android:orientation="vertical"> <EditText android:id="@+id/name" android:layout_width="match_parent" android:layout_height="wrap_content" android:ems="10" android:inputType="textPersonName" android:hint="name"/> <EditText android:id="@+id/mobile" android:layout_width="match_parent" android:layout_height="wrap_content" android:ems="10" android:inputType="phone" android:hint="Mobile"/> <Button android:id="@+id/Movetosecond" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Moving" /> </LinearLayout> |
MainActivity.kt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
package com.androindian.movekotlin import android.content.Intent import android.os.Bundle import androidx.appcompat.app.AppCompatActivity import kotlinx.android.synthetic.main.activity_main.* class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) Movetosecond.setOnClickListener { var intent= Intent(this@MainActivity,Second::class.java) //sending data intent.putExtra("Name",name.text.toString()) intent.putExtra("Mobile",mobile.text.toString()) startActivity(intent) } } } |
activiy_second.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".Second" android:orientation="vertical"> <Button android:id="@+id/button" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Button" /> </LinearLayout> |
Second.kt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
package com.androindian.movekotlin import android.content.Intent import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.widget.Toast import kotlinx.android.synthetic.main.activity_second.* class Second : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_second) var intent=intent var s1=intent.getStringExtra("Name") var s2=intent.getStringExtra("Mobile") Toast.makeText(this@Second,s1+s2,Toast.LENGTH_LONG).show() button.setOnClickListener { var intent= Intent(this@Second,Third::class.java) intent.putExtra("xyz",s1+s2) startActivity(intent) } } } |
activity_third.kt
1 2 3 4 5 6 7 8 9 |
<?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".Third"> </androidx.constraintlayout.widget.ConstraintLayout> |
Third.kt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
package com.androindian.movekotlin import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.widget.Toast class Third : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_third) var intent=intent var s1=intent.getStringExtra("xyz") Toast.makeText(this@Third,s1, Toast.LENGTH_LONG).show() } } |