Develop an Android app to
demonstrate the Activity using Button
• Intent is used to call an internal or external component from an
activity to another activity of another app
• Types of intent
• Explicit Intent
• Implicit Intent
The intent is the main component of Android app
development. The intent is the medium to pass between
components such as activities, content providers, broadcast
receivers, services, etc.
• Steps of Explicit Intent
• Initialization of Button on java file
• set Id([Link].ID_NAME), & onClicklistener on java file
• Onclick listener action on java file
• Intent Initialization
• Start Activity by passing initialized object on Intent
• Example of Explicit Intent
• Here we create an app that will open another activity on the same
app and we will move to the next window of the app by this.
• We will create two activities under this app and code the same in
both files except the button id we assign.
• Example of Implicit Intent
• Here we create a calling app where it will open the call app and call
the person whom we will define
• Steps of Implicit Intent
• Initialization of Button on java file
• set Id([Link].ID_NAME), & onClicklistener on java file
• Onclick listener action on java file
• Under onClick listener perform app permission and Intent
initialization
• Start Activity by passing initialized object on Intent
1. Create New Project
2. Open activity_main.xml
3. Change the Layout to RelativeLayout
4. Change the text : Activity-1
5. Create a Button ( ID ,text & position)
<?xml version="1.0" encoding="utf-8"?>
<TextView <RelativeLayout
android:id="@+id/textView" xmlns:android="[Link]
android:layout_width="wrap_content" android"
android:layout_height="wrap_content"
android:text="Activity-1" </RelativeLayout>
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"/>
<Button
android:id="@+id/button_A1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Go to Activity 2"
android:layout_below="@id/textView"
android:layout_centerHorizontal="true"/>
1. Create the activity_2
2. Open activity_2.xml
3. Change the Layout to RelativeLayout
4. Change the text : Activity-2
5. Create a Button ( ID ,text & position)
1. Create the activity-2
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Activity-2"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"/>
<Button
android:id="@+id/button_A2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Go to Activity 1"
android:layout_below="@id/textView"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
1. Open the [Link]
2. Open activity_2.xml
3. Change the Layout to RelativeLayout
4. Change the text : Activity-2
5. Create a Button ( ID ,text & position)
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity {
private Button button1 ;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
button1 = (Button) findViewById([Link].button_A1);// initialize the button from xml
[Link](new [Link]() {
@Override
public void onClick(View v) {
OpenActivity2();
}
});
}