Blog purpose for android basic example for android app developer. any query please my contact

Thursday, 17 December 2020

how to jump one activity to another activity in kotlin android


how to jump one activity to another activity in kotlin android


In this Tutorial how to jump one activity to another actvity in kotlin android programming example.

full Source code how to jump one activity to another actvity in kotlin android.


MainActivity.kt:

import android.support.v7.app.AppCompatActivity

import android.os.Bundle

import kotlinx.android.synthetic.main.activity_main.*

 

class MainActivity : AppCompatActivity() {

 

    override fun onCreate(savedInstanceState: Bundle?) {

        super.onCreate(savedInstanceState)

        setContentView(R.layout.activity_main)

 

        btnStartAnotherActivity.setOnClickListener {

            val intent = Intent(this, AnotherActivity::class.java)

            // start your next activity

            startActivity(intent)

        }

 

    }

}







2.activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:tools="http://schemas.android.com/tools"

    android:orientation="vertical"

    android:gravity="center"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    tools:context=".MainActivity">

 

    <TextView

        android:text="This is first Activity"

        android:textSize="25sp"

        android:padding="20sp"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content" />

 

    <Button

        android:id="@+id/btnStartAnotherActivity"

        android:text="Start Another Activity"

        android:textColor="#FFF"

        android:padding="20sp"

        android:background="#397bb2"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content" />

 

</LinearLayout>



3.AnotherActivity.kt:

import android.support.v7.app.AppCompatActivity

import android.os.Bundle

 

class AnotherActivity : AppCompatActivity() {

 

    override fun onCreate(savedInstanceState: Bundle?) {

        super.onCreate(savedInstanceState)

        setContentView(R.layout.activity_another)

    }

}




4.activity_another.xml:


<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:tools="http://schemas.android.com/tools"

    android:orientation="vertical"

    android:gravity="center"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    tools:context=".AnotherActivity">

 

    <TextView

        android:text="This is another Activity"

        android:textSize="25sp"

        android:padding="20sp"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content" />

 

</LinearLayout>

 





5.AndroidManifest.xml :


<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

   package="com.example.sairamkrishna.myapplication" >

  <uses-permission android:name="android.permission.CAMERA" />

   <application

      android:allowBackup="true"

      android:icon="@drawable/ic_launcher"

      android:label="@string/app_name"

      android:theme="@style/AppTheme" >

      

      <activity

         android:name="com.example.sairamkrishna.myapplication.MainActivity"

         android:label="@string/app_name" >

         

         <intent-filter>

            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />

         </intent-filter>

         

     </activity>

     

   </application>

</manifest>



 

No comments:

Post a Comment