Android Change Activity By Intent
Change Activity By Intent:
To change an activity is normally done by making use of an Intent (which simply means Intention).
Intent is an object containing a description of a task to be performed, and is used to initiate an activity, pass data between activities or do other operations within the boundaries of an Android application.
Example:
// activity_change_by_intent_example.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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ChangeActivityByIntentExample"
android:padding="16dp"
android:gravity="center"
android:orientation="vertical"
android:background="@color/colorAccent"
>
<Button
android:id="@+id/second"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Second Activity"
android:textColor="@color/colorWhite"
android:background="@color/colorOrange"/>
</LinearLayout>
// activity_second.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:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".SecondActivity"
android:padding="16dp"
android:gravity="center"
android:orientation="vertical"
android:background="@color/colorBrown" >
<Button
android:id="@+id/first"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="First Activity"
android:textColor="@color/colorWhite"
android:background="@color/colorAccent"/>
</LinearLayout>
Output