7
Most read
8
Most read
9
Most read
Intent
Prepared By: Ms. Soknigm Sa
1.What are intents?
- Intents are asynchronous messages which allow application components to
request functionality from other Android components. Intents allow you to
interact with components from the same applications as well as with
components contributed by other applications.
- Intents are objects of the android.content.Intent type
- An intent can contain data via a Bundle.
- There are 2 kind of intents: explicit and implicit intents.
Example of Intent
2. Starting activity or service
- To start an activity, use the
method startActivity(intent).
This method is defined on the
Context object which Activity
extends.
# Start the activity connect to the
# specified class
Intent i = new Intent(this, ActivityTwo.class);
startActivity(i);
3.1 Explicit Intent
- Explicit intents are typically used within an application as the classes in an
application are controlled or created by the application developer.
- The following shows how to create an explicit intent and send it to the Android
system to start an activity.
Intent i = new Intent(ActivityOne.this, ActivityTwo.class);
startActivity(intent); //start Activity
3.2 Implicit Intent
- Implicit intents specify the action which should be performed and optionally
data which provides content for the specific action and the fitting data typeof
android application.
- For example, the following tells the Android system to view a webpage. All
installed web browsers should be registered to the corresponding intent data via
an intent filter.
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(“www.tutorialpoint.com”));
startActivity(intent); //start Activity
Intent intent= new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(Uri.parse(“www.tutorialpoint.com”));
startActivity(intent); //start Activity
To Sum up
4. Data Transfer between Activity
- You can also add data directly to the Bundle or putExtra() methods of the Intent
objects.
- Extras are key/value pairs.
- The key is always of type String.
- As value you can use the primitive data types (int, float, …) , objects of
type String, Bundle, Parcelable and Serializable.
Example of using Bundle and putExtra()
Using Bundle
Bundle mBundle = new Bundle();
mBundle.putString("name", "Sokngim");
mBundle.putInt("age",24);
Intent testingIntent = new Intent(MainActivity.this, TestingActivity.class);
testingIntent.putExtras(mBundle);
startActivity(testingIntent);
Using putExtra()
Intent testingIntent = new Intent(MainActivity.this, TestingActivity.class);
testingIntent.putExtra("name", "Sokngim");
testingIntent.putExtra("age", 24);
startActivity(testingIntent);
4. Data Transfer between Activity
- The receiving component
can access this information
via the getAction() and
getData() methods on the
Intent object. This Intent
object can be retrieved via
the getIntent() method.
Bundle extras = getIntent().getExtras();
if (extras == null) {
return;
}
Log.d("mBundle", mBundle.getString("name"));
Log.d("mBundle", mBundle.getInt("age",0) + "");
// get data via the key
String value1 = extras.getString(Intent.EXTRA_TEXT);
if (value1 != null) {
// do something with the data
}
Intent Filter
An intent filter is an expression in an app's manifest file that specifies the type of intents that the
component would like to receive. <intent-filter> element in the manifest file to list down actions,
categories and data types associated with any activity, service, or broadcast receiver.
<activity android:name=".WebviewActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<action android:name="com.example.My Application.LAUNCH" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http" android:host="https://developer.android.com/index.html />
</intent-filter>
</activity>
Intent intent = new Intent (Intent.ACTION_VIEW,
Uri.parse("https://developer.android.com/index.html"));
startActivity(intent);
Example of Using Intent
- Opening new activity
- Passing data between activities
- Launching the built-in web browser and supplying a URL address
- Launching the web browser and supplying a search string
- Launching the built-in Dialer application and supplying a phone number
- Launching Google Street View and supplying a location
- Launching the built-in Camera application in still or video mode
- Launching a ringtone picker

More Related Content

PPTX
Android activity lifecycle
PDF
Android: Intent, Intent Filter, Broadcast Receivers
PDF
Android intents
PPTX
Android User Interface
PDF
Android activity
PDF
Android Fragment
PDF
Android Basic Components
PPTX
Android Services
Android activity lifecycle
Android: Intent, Intent Filter, Broadcast Receivers
Android intents
Android User Interface
Android activity
Android Fragment
Android Basic Components
Android Services

What's hot (20)

PPTX
04 activities and activity life cycle
PPT
Intent, Service and BroadcastReciver (2).ppt
PPT
android activity
PPT
Day 4: Android: UI Widgets
PPTX
Android Intent.pptx
PPTX
Notification android
PDF
Android notification
PPTX
Broadcast Receiver
PDF
Introduction to fragments in android
PPTX
Android share preferences
PDF
Android Threading
PDF
Intents in Android
PPTX
Presentation on Android application life cycle and saved instancestate
PPT
Android lifecycle
PDF
Fragments In Android
PDF
Android Multimedia Support
PDF
Introduction to Android Development
PDF
Android ui menu
PPTX
Android UI
PDF
Android Components & Manifest
04 activities and activity life cycle
Intent, Service and BroadcastReciver (2).ppt
android activity
Day 4: Android: UI Widgets
Android Intent.pptx
Notification android
Android notification
Broadcast Receiver
Introduction to fragments in android
Android share preferences
Android Threading
Intents in Android
Presentation on Android application life cycle and saved instancestate
Android lifecycle
Fragments In Android
Android Multimedia Support
Introduction to Android Development
Android ui menu
Android UI
Android Components & Manifest
Ad

Similar to 05 intent (20)

PDF
Tut123456.pdf
PPTX
Pertemuan 03 - Activities and intents.pptx
PPT
Android - Android Intent Types
PPTX
Data Transfer between activities and Database
PPT
Level 1 &amp; 2
DOCX
Android intents in android application-chapter7
PPTX
Android - Intents and Filters hgfh gfh.pptx
PPTX
learn about Android Extended Intents.pptx
PPTX
Intents in Mobile Application Development.pptx
PDF
Android Lesson 3 - Intent
PPTX
MAD Unit 5.pptxxxxxxxxxxxxxxxxxxxxxxxxxx
PDF
Android App Development 07 : Intent &amp; Share
PPT
Android Bootcamp Tanzania:intents
PPTX
Tk2323 lecture 3 intent
PPTX
Data Transfer between Activities & Databases
DOCX
Using intents in android
ODP
Ppt 2 android_basics
PPT
ANDROID
PPTX
unit3.pptx
PPTX
Android webinar class_3
Tut123456.pdf
Pertemuan 03 - Activities and intents.pptx
Android - Android Intent Types
Data Transfer between activities and Database
Level 1 &amp; 2
Android intents in android application-chapter7
Android - Intents and Filters hgfh gfh.pptx
learn about Android Extended Intents.pptx
Intents in Mobile Application Development.pptx
Android Lesson 3 - Intent
MAD Unit 5.pptxxxxxxxxxxxxxxxxxxxxxxxxxx
Android App Development 07 : Intent &amp; Share
Android Bootcamp Tanzania:intents
Tk2323 lecture 3 intent
Data Transfer between Activities & Databases
Using intents in android
Ppt 2 android_basics
ANDROID
unit3.pptx
Android webinar class_3
Ad

More from Sokngim Sa (8)

PPTX
06 UI Layout
PPTX
How to decompile apk
PPTX
03 android application structure
PPTX
02 getting start with android app development
PPTX
01 introduction to android
PPTX
Add eclipse project with git lab
PPTX
Transmitting network data using volley(14 09-16)
PPTX
C Programming: Control Structure
06 UI Layout
How to decompile apk
03 android application structure
02 getting start with android app development
01 introduction to android
Add eclipse project with git lab
Transmitting network data using volley(14 09-16)
C Programming: Control Structure

Recently uploaded (20)

PPTX
20th Century Theater, Methods, History.pptx
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PDF
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
PPTX
Unit 4 Computer Architecture Multicore Processor.pptx
PDF
احياء السادس العلمي - الفصل الثالث (التكاثر) منهج متميزين/كلية بغداد/موهوبين
PPTX
Share_Module_2_Power_conflict_and_negotiation.pptx
PDF
Uderstanding digital marketing and marketing stratergie for engaging the digi...
PDF
advance database management system book.pdf
PDF
Vision Prelims GS PYQ Analysis 2011-2022 www.upscpdf.com.pdf
PDF
Paper A Mock Exam 9_ Attempt review.pdf.
PDF
AI-driven educational solutions for real-life interventions in the Philippine...
PDF
Τίμαιος είναι φιλοσοφικός διάλογος του Πλάτωνα
PDF
IGGE1 Understanding the Self1234567891011
PDF
HVAC Specification 2024 according to central public works department
PDF
What if we spent less time fighting change, and more time building what’s rig...
PDF
LDMMIA Reiki Yoga Finals Review Spring Summer
PPTX
B.Sc. DS Unit 2 Software Engineering.pptx
PDF
Empowerment Technology for Senior High School Guide
PDF
FORM 1 BIOLOGY MIND MAPS and their schemes
PDF
David L Page_DCI Research Study Journey_how Methodology can inform one's prac...
20th Century Theater, Methods, History.pptx
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
Unit 4 Computer Architecture Multicore Processor.pptx
احياء السادس العلمي - الفصل الثالث (التكاثر) منهج متميزين/كلية بغداد/موهوبين
Share_Module_2_Power_conflict_and_negotiation.pptx
Uderstanding digital marketing and marketing stratergie for engaging the digi...
advance database management system book.pdf
Vision Prelims GS PYQ Analysis 2011-2022 www.upscpdf.com.pdf
Paper A Mock Exam 9_ Attempt review.pdf.
AI-driven educational solutions for real-life interventions in the Philippine...
Τίμαιος είναι φιλοσοφικός διάλογος του Πλάτωνα
IGGE1 Understanding the Self1234567891011
HVAC Specification 2024 according to central public works department
What if we spent less time fighting change, and more time building what’s rig...
LDMMIA Reiki Yoga Finals Review Spring Summer
B.Sc. DS Unit 2 Software Engineering.pptx
Empowerment Technology for Senior High School Guide
FORM 1 BIOLOGY MIND MAPS and their schemes
David L Page_DCI Research Study Journey_how Methodology can inform one's prac...

05 intent

  • 2. 1.What are intents? - Intents are asynchronous messages which allow application components to request functionality from other Android components. Intents allow you to interact with components from the same applications as well as with components contributed by other applications. - Intents are objects of the android.content.Intent type - An intent can contain data via a Bundle. - There are 2 kind of intents: explicit and implicit intents.
  • 4. 2. Starting activity or service - To start an activity, use the method startActivity(intent). This method is defined on the Context object which Activity extends. # Start the activity connect to the # specified class Intent i = new Intent(this, ActivityTwo.class); startActivity(i);
  • 5. 3.1 Explicit Intent - Explicit intents are typically used within an application as the classes in an application are controlled or created by the application developer. - The following shows how to create an explicit intent and send it to the Android system to start an activity. Intent i = new Intent(ActivityOne.this, ActivityTwo.class); startActivity(intent); //start Activity
  • 6. 3.2 Implicit Intent - Implicit intents specify the action which should be performed and optionally data which provides content for the specific action and the fitting data typeof android application. - For example, the following tells the Android system to view a webpage. All installed web browsers should be registered to the corresponding intent data via an intent filter. Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(“www.tutorialpoint.com”)); startActivity(intent); //start Activity Intent intent= new Intent(); intent.setAction(Intent.ACTION_VIEW); intent.setData(Uri.parse(“www.tutorialpoint.com”)); startActivity(intent); //start Activity
  • 8. 4. Data Transfer between Activity - You can also add data directly to the Bundle or putExtra() methods of the Intent objects. - Extras are key/value pairs. - The key is always of type String. - As value you can use the primitive data types (int, float, …) , objects of type String, Bundle, Parcelable and Serializable.
  • 9. Example of using Bundle and putExtra() Using Bundle Bundle mBundle = new Bundle(); mBundle.putString("name", "Sokngim"); mBundle.putInt("age",24); Intent testingIntent = new Intent(MainActivity.this, TestingActivity.class); testingIntent.putExtras(mBundle); startActivity(testingIntent); Using putExtra() Intent testingIntent = new Intent(MainActivity.this, TestingActivity.class); testingIntent.putExtra("name", "Sokngim"); testingIntent.putExtra("age", 24); startActivity(testingIntent);
  • 10. 4. Data Transfer between Activity - The receiving component can access this information via the getAction() and getData() methods on the Intent object. This Intent object can be retrieved via the getIntent() method. Bundle extras = getIntent().getExtras(); if (extras == null) { return; } Log.d("mBundle", mBundle.getString("name")); Log.d("mBundle", mBundle.getInt("age",0) + ""); // get data via the key String value1 = extras.getString(Intent.EXTRA_TEXT); if (value1 != null) { // do something with the data }
  • 11. Intent Filter An intent filter is an expression in an app's manifest file that specifies the type of intents that the component would like to receive. <intent-filter> element in the manifest file to list down actions, categories and data types associated with any activity, service, or broadcast receiver. <activity android:name=".WebviewActivity" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.VIEW" /> <action android:name="com.example.My Application.LAUNCH" /> <category android:name="android.intent.category.DEFAULT" /> <data android:scheme="http" android:host="https://developer.android.com/index.html /> </intent-filter> </activity> Intent intent = new Intent (Intent.ACTION_VIEW, Uri.parse("https://developer.android.com/index.html")); startActivity(intent);
  • 12. Example of Using Intent - Opening new activity - Passing data between activities - Launching the built-in web browser and supplying a URL address - Launching the web browser and supplying a search string - Launching the built-in Dialer application and supplying a phone number - Launching Google Street View and supplying a location - Launching the built-in Camera application in still or video mode - Launching a ringtone picker