Reading
Add Comment
What is Intent and what are the types of it ?
It is by and large utilized with startActivity() strategy to conjure action, telecast recipients and so forth.
The word reference significance of purpose is proposition or reason. Thus, it can be portrayed as the aim to do activity.
The LabeledIntent is the subclass of android.content.Intent class.
Android expectations are essentially used to:
- Start the service
- Launch an activity
- Display a web page
- Display a list of contacts
- Broadcast a message
- Dial a phone call etc.
Types of Android Intents
There are two types of intents in android: implicit and explicit.
1) Implicit Intent
Implicit Intent doesn't specifiy the component. In such case, intent provides information of available components provided by the system that is to be invoked.
For example, you may write the following code to view the webpage.
intent.setData(Uri.parse("http://dheeruapps.blogspot.com"));
startActivity(intent);
2) Explicit Intent
Explicit Intent specifies the component. In such case, intent provides the external class to be invoked.
Intent i = new Intent(getApplicationContext(), ActivityTwo.class);
startActivity(i);
startActivity(i);
Android Implicit Intent Example
activity_main.xml
File: activity_main.xml
<RelativeLayout xmlns:androclass="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=".MainActivity" >
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="44dp"
android:ems="10" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/editText1"
android:layout_centerHorizontal="true"
android:layout_marginTop="54dp"
android:text="Visit" />
</RelativeLayout>
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="44dp"
android:ems="10" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/editText1"
android:layout_centerHorizontal="true"
android:layout_marginTop="54dp"
android:text="Visit" />
</RelativeLayout>
Activity class
File: MainActivity.java
0 comments:
Post a Comment