SlideShare a Scribd company logo
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

What's hot

Android UI
Android UIAndroid UI
Android UI
nationalmobileapps
 
Introduction to fragments in android
Introduction to fragments in androidIntroduction to fragments in android
Introduction to fragments in android
Prawesh Shrestha
 
Android User Interface
Android User InterfaceAndroid User Interface
Android User Interface
Shakib Hasan Sumon
 
Intent in android
Intent in androidIntent in android
Intent in android
Durai S
 
Notification android
Notification androidNotification android
Notification android
ksheerod shri toshniwal
 
Android - Application Framework
Android - Application FrameworkAndroid - Application Framework
Android - Application Framework
Yong Heui Cho
 
Android Intent.pptx
Android Intent.pptxAndroid Intent.pptx
Android Intent.pptx
vishal choudhary
 
Layouts in android
Layouts in androidLayouts in android
Layouts in android
Durai S
 
android layouts
android layoutsandroid layouts
android layoutsDeepa Rani
 
UI controls in Android
UI controls in Android UI controls in Android
UI controls in Android
DivyaKS12
 
Android activities & views
Android activities & viewsAndroid activities & views
Android activities & views
ma-polimi
 
Intents in Android
Intents in AndroidIntents in Android
Intents in Android
ma-polimi
 
android activity
android activityandroid activity
android activityDeepa Rani
 
Android resources
Android resourcesAndroid resources
Android resources
ma-polimi
 
Android: Intent, Intent Filter, Broadcast Receivers
Android: Intent, Intent Filter, Broadcast ReceiversAndroid: Intent, Intent Filter, Broadcast Receivers
Android: Intent, Intent Filter, Broadcast Receivers
CodeAndroid
 
Android application structure
Android application structureAndroid application structure
Android application structureAlexey Ustenko
 
Android animation
Android animationAndroid animation
Android animationKrazy Koder
 
Mobile Application Development With Android
Mobile Application Development With AndroidMobile Application Development With Android
Mobile Application Development With Android
guest213e237
 

What's hot (20)

Android UI
Android UIAndroid UI
Android UI
 
Introduction to fragments in android
Introduction to fragments in androidIntroduction to fragments in android
Introduction to fragments in android
 
Android User Interface
Android User InterfaceAndroid User Interface
Android User Interface
 
Intent in android
Intent in androidIntent in android
Intent in android
 
Notification android
Notification androidNotification android
Notification android
 
Android - Application Framework
Android - Application FrameworkAndroid - Application Framework
Android - Application Framework
 
Android Intent.pptx
Android Intent.pptxAndroid Intent.pptx
Android Intent.pptx
 
android menus
android menusandroid menus
android menus
 
Layouts in android
Layouts in androidLayouts in android
Layouts in android
 
android layouts
android layoutsandroid layouts
android layouts
 
UI controls in Android
UI controls in Android UI controls in Android
UI controls in Android
 
Android activities & views
Android activities & viewsAndroid activities & views
Android activities & views
 
Intents in Android
Intents in AndroidIntents in Android
Intents in Android
 
android activity
android activityandroid activity
android activity
 
AndroidManifest
AndroidManifestAndroidManifest
AndroidManifest
 
Android resources
Android resourcesAndroid resources
Android resources
 
Android: Intent, Intent Filter, Broadcast Receivers
Android: Intent, Intent Filter, Broadcast ReceiversAndroid: Intent, Intent Filter, Broadcast Receivers
Android: Intent, Intent Filter, Broadcast Receivers
 
Android application structure
Android application structureAndroid application structure
Android application structure
 
Android animation
Android animationAndroid animation
Android animation
 
Mobile Application Development With Android
Mobile Application Development With AndroidMobile Application Development With Android
Mobile Application Development With Android
 

Similar to 05 intent

Android intents in android application-chapter7
Android intents in android application-chapter7Android intents in android application-chapter7
Android intents in android application-chapter7
Dr. Ramkumar Lakshminarayanan
 
Intent, Service and BroadcastReciver (2).ppt
Intent, Service and BroadcastReciver (2).pptIntent, Service and BroadcastReciver (2).ppt
Intent, Service and BroadcastReciver (2).ppt
BirukMarkos
 
unit3.pptx
unit3.pptxunit3.pptx
unit3.pptx
sunilsoni446112
 
Level 1 &amp; 2
Level 1 &amp; 2Level 1 &amp; 2
Level 1 &amp; 2
skumartarget
 
Lab1-android
Lab1-androidLab1-android
Lab1-android
Lilia Sfaxi
 
ANDROID
ANDROIDANDROID
ANDROID
DrMeftahZouai
 
Android - Intents - Mazenet Solution
Android - Intents - Mazenet SolutionAndroid - Intents - Mazenet Solution
Android - Intents - Mazenet Solution
Mazenetsolution
 
Android Lesson 3 - Intent
Android Lesson 3 - IntentAndroid Lesson 3 - Intent
Android Lesson 3 - Intent
Daniela Da Cruz
 
Android Bootcamp Tanzania:intents
Android Bootcamp Tanzania:intentsAndroid Bootcamp Tanzania:intents
Android Bootcamp Tanzania:intents
Denis Minja
 
Android App Development - 02 Activity and intent
Android App Development - 02 Activity and intentAndroid App Development - 02 Activity and intent
Android App Development - 02 Activity and intent
Diego Grancini
 
Android App Development 07 : Intent &amp; Share
Android App Development 07 : Intent &amp; ShareAndroid App Development 07 : Intent &amp; Share
Android App Development 07 : Intent &amp; ShareAnuchit Chalothorn
 
Android activity intentsq
Android activity intentsqAndroid activity intentsq
Android activity intentsqperpetrotech
 
Android activity intents
Android activity intentsAndroid activity intents
Android activity intentsperpetrotech
 
Pertemuan 03 - Activities and intents.pptx
Pertemuan 03 - Activities and intents.pptxPertemuan 03 - Activities and intents.pptx
Pertemuan 03 - Activities and intents.pptx
MUHAMMADRIFKIPERMANA2
 
Tk2323 lecture 3 intent
Tk2323 lecture 3   intentTk2323 lecture 3   intent
Tk2323 lecture 3 intent
MengChun Lam
 
Android webinar class_3
Android webinar class_3Android webinar class_3
Android webinar class_3Edureka!
 
Android Intent and intent filters
Android Intent and intent filtersAndroid Intent and intent filters
Android Intent and intent filters
Gowtham Kumar
 
Using intents in android
Using intents in androidUsing intents in android
Using intents in android
Oum Saokosal
 
DAY2.pptx
DAY2.pptxDAY2.pptx

Similar to 05 intent (20)

Android intents in android application-chapter7
Android intents in android application-chapter7Android intents in android application-chapter7
Android intents in android application-chapter7
 
Intent, Service and BroadcastReciver (2).ppt
Intent, Service and BroadcastReciver (2).pptIntent, Service and BroadcastReciver (2).ppt
Intent, Service and BroadcastReciver (2).ppt
 
unit3.pptx
unit3.pptxunit3.pptx
unit3.pptx
 
Level 1 &amp; 2
Level 1 &amp; 2Level 1 &amp; 2
Level 1 &amp; 2
 
Lab1-android
Lab1-androidLab1-android
Lab1-android
 
ANDROID
ANDROIDANDROID
ANDROID
 
Android - Intents - Mazenet Solution
Android - Intents - Mazenet SolutionAndroid - Intents - Mazenet Solution
Android - Intents - Mazenet Solution
 
Android Lesson 3 - Intent
Android Lesson 3 - IntentAndroid Lesson 3 - Intent
Android Lesson 3 - Intent
 
Android Bootcamp Tanzania:intents
Android Bootcamp Tanzania:intentsAndroid Bootcamp Tanzania:intents
Android Bootcamp Tanzania:intents
 
Android App Development - 02 Activity and intent
Android App Development - 02 Activity and intentAndroid App Development - 02 Activity and intent
Android App Development - 02 Activity and intent
 
Android App Development 07 : Intent &amp; Share
Android App Development 07 : Intent &amp; ShareAndroid App Development 07 : Intent &amp; Share
Android App Development 07 : Intent &amp; Share
 
Android activity intentsq
Android activity intentsqAndroid activity intentsq
Android activity intentsq
 
Android activity intents
Android activity intentsAndroid activity intents
Android activity intents
 
Pertemuan 03 - Activities and intents.pptx
Pertemuan 03 - Activities and intents.pptxPertemuan 03 - Activities and intents.pptx
Pertemuan 03 - Activities and intents.pptx
 
Tk2323 lecture 3 intent
Tk2323 lecture 3   intentTk2323 lecture 3   intent
Tk2323 lecture 3 intent
 
Android webinar class_3
Android webinar class_3Android webinar class_3
Android webinar class_3
 
Android Intent and intent filters
Android Intent and intent filtersAndroid Intent and intent filters
Android Intent and intent filters
 
Using intents in android
Using intents in androidUsing intents in android
Using intents in android
 
Intents are Awesome
Intents are AwesomeIntents are Awesome
Intents are Awesome
 
DAY2.pptx
DAY2.pptxDAY2.pptx
DAY2.pptx
 

More from Sokngim Sa

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

More from Sokngim Sa (8)

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

Recently uploaded

Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 

Recently uploaded (20)

Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 

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