Android - Intents - Mazenet Solution
-
Upload
mazenetsolution -
Category
Education
-
view
71 -
download
0
Transcript of Android - Intents - Mazenet Solution
Intents
BySharmilee
Java TrainerMazenet Solution
• Intents are asynchronous messages• It allow you to interact with components• Types of Intent– Implicit Intent– Explicit Intent
Starting Activities
• To start an activity, use the method
startActivity(intent)
• This method is defined on the Context object which Activity extends.
• Activities which are started by other Android activities are called sub-activities.
Intent i = new Intent(this, ActivityTwo.class);startActivity(i);
Types of Intent
1. Explicit Intents
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");
2. Implicit Intents
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);
Retrieving result data from a sub-activity
Example
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); }
Intent Filter
• 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.
String url = "http://www.mazenetsolution.com"; Intent i = new Intent(Intent.ACTION_VIEW);i.setData(Uri.parse(url)); startActivity(i);
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>
Nungambakkam, ChennaiWebsite: www.mazenetsolution.com
www.mazenet-chennai.in Mobile : 9677718889