Android - Intents - Mazenet Solution

21
Intents By Sharmilee Java Trainer Mazenet Solution

Transcript of Android - Intents - Mazenet Solution

Page 1: Android - Intents - Mazenet Solution

Intents

BySharmilee

Java TrainerMazenet Solution

Page 2: Android - Intents - Mazenet Solution

• Intents are asynchronous messages• It allow you to interact with components• Types of Intent– Implicit Intent– Explicit Intent

Page 3: Android - Intents - Mazenet Solution
Page 4: Android - Intents - Mazenet Solution

Starting Activities

• To start an activity, use the method

startActivity(intent)

• This method is defined on the Context object which Activity extends.

Page 5: Android - Intents - Mazenet Solution
Page 6: Android - Intents - Mazenet Solution

• Activities which are started by other Android activities are called sub-activities.

Intent i = new Intent(this, ActivityTwo.class);startActivity(i);

Page 7: Android - Intents - Mazenet Solution

Types of Intent

Page 8: Android - Intents - Mazenet Solution

1. Explicit Intents

Page 9: Android - Intents - Mazenet Solution

Explicit Intents

• It explicitly define the component which should be called by the Android system, by using the Java class as identifier.

Intent i = new Intent(this, ActivityTwo.class); i.putExtra("Value1", "This value one for ActivityTwo "); i.putExtra("Value2", "This value two ActivityTwo");

Page 10: Android - Intents - Mazenet Solution

2. Implicit Intents

Page 11: Android - Intents - Mazenet Solution

Implicit Intents

• Implicit intents specify the action which should be performed and optionally data which provides content for the action.

• For Example: the following tells the Android System to view a web page.

Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.mazenetsolution.com")); startActivity(i);

Page 12: Android - Intents - Mazenet Solution

Retrieving result data from a sub-activity

Page 13: Android - Intents - Mazenet Solution
Page 14: Android - Intents - Mazenet Solution
Page 15: Android - Intents - Mazenet Solution

Example

Page 16: Android - Intents - Mazenet Solution

startActivityForResult()

public void onClick(View view) { Intent i = new Intent(this, ActivityTwo.class); i.putExtra("Value1", "This value one for ActivityTwo "); i.putExtra("Value2", "This value two ActivityTwo"); startActivityForResult(i, REQUEST_CODE); }

Page 17: Android - Intents - Mazenet Solution

Intent Filter

Page 18: Android - Intents - Mazenet Solution

• Intents are used to signal to the Android system that a certain event has occurred.

• Intents often describe the action which should be performed and provide data upon which such an action should be done.

Page 19: Android - Intents - Mazenet Solution

String url = "http://www.mazenetsolution.com"; Intent i = new Intent(Intent.ACTION_VIEW);i.setData(Uri.parse(url)); startActivity(i);

Page 20: Android - Intents - Mazenet Solution

Example: Register an activity as browser

<activity android:name=".BrowserActivitiy" android:label="@string/app_name">

<intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <data android:scheme="http"/> </intent-filter> </activity>

Page 21: Android - Intents - Mazenet Solution

Nungambakkam, ChennaiWebsite: www.mazenetsolution.com

www.mazenet-chennai.in Mobile : 9677718889