About Intents in Android
8 pages
English

About Intents in Android

-

Le téléchargement nécessite un accès à la bibliothèque YouScribe
Tout savoir sur nos offres
8 pages
English
Le téléchargement nécessite un accès à la bibliothèque YouScribe
Tout savoir sur nos offres

Description

About Intents in Android Intents are asynchronous message which allow application components to request functionality from other Android components. The dictionary meaning of Intent is Intention or purpose. So it can be described as the intention to do action. Android intentis the message that is passed between components such as content providers, activities, broadcast receivers, services etc. Android Intentsare mainly used to:      start a service dial a phone call Broadcast a message Display a list of contacts Display a web page The LabeledIntent is the subclass of android.content.Intent class. An intent can contain data via a Bundle. This data can be used by the receiving component. In Android the reuse of other application components is a concept known as task. An application can access other Android components to achieve a task. Starting activities or services: To start an activity you have to use a method startActivity().This method is deined the Context object which Activity extends. The following code demonstrates how you can start activity via intent. http://tecorb.com Intent i = new Intent (this,Login.class); startActivity(i); Activities which are started by other android activities are called subactivities. To start a service via intents, use the startService(Intent) method call.

Informations

Publié par
Publié le 09 mai 2017
Nombre de lectures 1
Langue English

Extrait

About Intents in Android
Intents are asynchronous message which allow application components to request functionality from other Android components.
The dictionary meaning of Intent is Intention or purpose. So it can be described as the intention to do action.
Android intentis the message that is passed between components such as content providers, activities, broadcast receivers, services etc.
Android Intentsare mainly used to:
start a service
dial a phone call
Broadcast a message
Display a list of contacts
Display a web page
The LabeledIntent is the subclass of android.content.Intent class.
An intent can contain data via a Bundle. This data can be used by the receiving component.
In Android the reuse of other application components is a concept known as task. An application can access other Android components to achieve a task.
Starting activities or services:
To start an activity you have to use a method startActivity().This method is deîned the Context object which Activity extends.
The following code demonstrates how you can start activity via intent.
http://tecorb.com
Intent i = new Intent (this,Login.class);
startActivity(i);
Activities which are started by other android activities are called sub-activities. To start a service via intents, use the startService(Intent) method call.
Types of Android Intents:
There are two types of Intents in android which are as follows:
Implicit Intent
Explicit Intent
Implicit Intent:
These Intents do not name a target and the îeld for the component name is left blank. Implicit Intents are also used to activate components of other activities. http://tecorb.com
for example-
Intent i= new Intent();
i.setAction(android.content.Intent.ACTION_VIEW);
i.setData(ContactsContracts.CONTENT_URI);
startActivity(i);
Explicit Intent:
Explicit intent going to be connected intenal world of application. Explicit Intent speciîes the components. In such case,intent provides the external class to be invoked.
For example-
Intent i= new Intent();
startActivity(this,First.class));
Let's see a simple example of Intent that take from one activity to another activity.
First Activity XML:
<?xml version="1.0"encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="center_horizontal" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingBottom="@dimen/activity_horizontal_margin" android:gravity="center_horizontal" android:background="#bcbaba">
http://tecorb.com
<LinearLayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="wrap_content"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="? android:attr/textAppearanceSmall" android:text="Email" android:id="@+id/textView9" android:layout_marginBottom="4dp" android:textSize="20sp" android:textColor="#ffffff"/> <LinearLayout android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#fff" android:layout_weight="1"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/imageView3" android:background="@drawable/email_icon" android:layout_gravity="left|center_horizontal"/> <EditText style="@style/signupEditText" android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="textPersonName" android:ems="10" android:id="@+id/edtEmail" android:layout_centerVertical="true" android:layout_centerHorizontal="true" android:hint="Email" android:gravity="center_vertical" android:paddingTop="5dp" android:paddingBottom="5dp"/> </LinearLayout> </LinearLayout> <LinearLayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="5dp" http://tecorb.com
android:paddingTop="5dp"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="? android:attr/textAppearanceSmall" android:text="Password" android:id="@+id/textView10" android:layout_marginBottom="4dp" android:textSize="20sp" android:textColor="#ffffff"/> <LinearLayout android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#fff" android:layout_weight="1"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/imageView9" android:background="@drawable/password_icon" android:layout_gravity="left|center_horizontal"/> <EditText style="@style/signupEditText" android:layout_width="match_parent" android:layout_height="wrap_content" android:ems="10" android:id="@+id/edtPassword" android:layout_centerVertical="true" android:layout_centerHorizontal="true" android:hint="*******" android:gravity="center_vertical" android:inputType="textPassword" android:paddingTop="5dp" android:paddingBottom="5dp"/> </LinearLayout> </LinearLayout> <LinearLayout android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center_horizontal"> </LinearLayout> <LinearLayout android:orientation="vertical" http://tecorb.com
android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center_horizontal"> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/btnSignIn" android:onClick="onClick" android:layout_gravity="center_horizontal" android:gravity="center" android:background="#fff" android:layout_marginTop="25dp" android:text="LOGIN" android:textColor="#238996" android:textSize="18sp"/> </LinearLayout> </LinearLayout>
Second Activity XML:
<?xml version="1.0"encoding="utf-8"?>
<RelativeLayout 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" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.example.tecorb.eat_we_go.Second" android:background="#c5bebe"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Welcome" android:id="@+id/textView6" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_marginTop="195dp" android:textStyle="bold" http://tecorb.com
android:textSize="30sp" android:textColor="#1d1717"/> </RelativeLayout>
First.java
packagecom.example.tecorb.eat_we_go;
importandroid.content.Intent; importandroid.support.v7.app.AppCompatActivity; importandroid.os.Bundle; importandroid.view.View; importandroid.widget.Button; importandroid.widget.EditText; public classFirstextendsAppCompatActivity { EditTextedtEmail,edtPassword; ButtonbtnSignIn; @Override protected voidonCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_first); edtEmail= (EditText) findViewById(R.id.edtEmail); edtPassword= (EditText) findViewById(R.id.edtPassword); btnSignIn=(Button)findViewById(R.id.btnSignIn); btnSignIn.setOnClickListener(newView.OnClickListener() { @Override public voidonClick(View v) { Intent intent=newIntent(); startActivity(newIntent(getApplicationContext(), Second.class)); } }); } }
In above example, there are two xml activity in which îrst is our main and login activity in which we take two edit text for email and password and a login button to submit the data by which on click we reach at the other activity where we take an edit text and show welcome as a text.
http://tecorb.com
With the help of java we write code and by intent we connect two activities as îrst activity with the second.
http://tecorb.com
  • Univers Univers
  • Ebooks Ebooks
  • Livres audio Livres audio
  • Presse Presse
  • Podcasts Podcasts
  • BD BD
  • Documents Documents