SlideShare una empresa de Scribd logo
1 de 23
Descargar para leer sin conexión
Israel Ferrer
  Android Lover since 2008
     cofounder bubiloop
    cofounder android.es
  Barcelona GTUG Leader
   Android Dev at Fever
Head Mobile Dept. at ASMWS
 Computer Science at LaSalle
INTENTS
ARE AWESOME
   really, trust me!



                       Israel Ferrer
                            14th March
WHAT ARE

INTENTS
    ?
intent |inˈtent| noun
 intention or purpose:
with alarm she realized his
intent | a real intent to cut back
on social programs.




                                     flickr: chinesetealover
OK... WHAT DOES THIS REALLY MEAN?
Open new Screens
   Share with other apps
Open Camera to take a photo
    Open file manager
    Open the browser
  Open QR Code Scanner
             ...
HOW INTENTS

WORK
     ?
Explicit Intent


Implicit Intent



                  theatricalintelligence
EXPLICIT INTENTS

• Explicit
         Intent names the component which should be called
 by the Android system, using the Java class as identifier.

• Used   to open new activities in the same app.
         final Intent intent=new Intent(this, LoginActivity.class);
         startActivity(intent);
IMPLICIT INTENTS
• Implicitintent specifies the action to perform and optionally an
  URI for the action.

• Implicit
         Intent is managed by Android Intent resolution, which
  maps the intent to a Service, Activity or Broadcasts Receiver

• Thisresolution is done by matching intent with intentFilters of
  every app.

• Ifmore than one app can handle the action, the user will have
  to choose.
       final Intent intent=new Intent(Intent.ACTION_VIEW, "http://mylookout.com");
SHARE DATA

• Intents        can contain aditional data by using putExtra() method
  •       intent.putExtra(EXTRA_CONVERSATION, conversation);



• the
    receiving component can obtain this data by getExtras()
 method
      Bundle extras = getIntent().getExtras();
      String conversation = extras.getString(EXTRA_CONVERSATION);
      if (conversation != null) {
      	 // Do something with the data
      }
INTENT FILTERS
• AnIntentFilter specifies the types of Intent that an activity,
 service, or broadcast receiver can respond to. IntentFilters are
 declared in the Android Manifest.

• There   are 3 pieces of information used for this resolution:

 • Action

 • Type: mymeType      or scheme.

 • Category: need    to support DEFAULT to be found by
   startActivity.
INTENT FILTERS
Intent
final Intent intent=new Intent(Intent.ACTION_VIEW, "http://mylookout.com");



IntentFilter
<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>
TO SUM UP

• Explicit: choose    the component to call.

• Implicit: isa general intent with action and optionally URI.
 The Intent resolution call the component that can handle it.

• Intents   can share data between components and apps.
HOW TO

USE
INTENTS
   ?
• Reuse   code and functionality from 3rd party apps

 • ACTION_SEND

 • ACTION_VIEW

   • geo:lat,lon   to open map

   • http://host   to open browser

   • tel:number    to open dialer
• Define    a set of intents to handle web addresses.

• Example: Twitter

  • Define    IntentFilter to handle twitter urls

   <activity android:name=".UrlHandleActivity" android:label="@string/app_name">
     <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <data android:host="www.twitter.com" android:scheme="http" />
     </intent-filter>
   </activity>
• Check   the URL path to fire target Activity
   public void onCreate(Bundle savedInstanceState)
   	   {
   	     super.onCreate(savedInstanceState);
   	
   	     Uri uri = getIntent().getData();
   	     if (null == uri) {
   	       // Shouldn't happen. Handle errors.
   	       finish();
   	       return;
   	     }

   	    String path = uri.getPath();
   	    for (Pair<String, Class> pair : DISPATCH_MAP) {
   	      if (path.matches(pair.mFirst)) {
   	        Intent intent = new Intent(this, pair.mSecond);
   	        intent.setData(uri);
   	        startActivity(intent);
   	        finish();
   	        return;
   	      }
   	    }
   	   	    finish();
   	   }
   	   private static final List<Pair<String, Class>> DISPATCH_MAP
       = new LinkedList<Pair<String, Class>>();
   static {
     DISPATCH_MAP.add(new Pair<String, Class>("(.*)/status$",
       TweetActivity.class));
     DISPATCH_MAP.add(new Pair<String, Class>("/another/path",
       ProfileActivity.class));
   }
• Exposeintents to 3rd party apps. Example: Lookout public
 backup intent.
CONCLUSIONS
A core component of Android.
 A way to reuse functionality between apps.
         The glue between activities.
The mashup concept into a mobile platform
Intents are Awesome for users & developers
QUESTIONS?
Intents are Awesome

Más contenido relacionado

La actualidad más candente

Android intents, notification and broadcast recievers
Android intents, notification and broadcast recieversAndroid intents, notification and broadcast recievers
Android intents, notification and broadcast recievers
Utkarsh Mankad
 
Day 4: Activity lifecycle
Day 4: Activity lifecycleDay 4: Activity lifecycle
Day 4: Activity lifecycle
Ahsanul Karim
 
Android activity
Android activityAndroid activity
Android activity
Krazy Koder
 
Android activity, service, and broadcast recievers
Android activity, service, and broadcast recieversAndroid activity, service, and broadcast recievers
Android activity, service, and broadcast recievers
Utkarsh Mankad
 

La actualidad más candente (19)

Using intents in android
Using intents in androidUsing intents in android
Using intents in android
 
Presentation on Android application life cycle and saved instancestate
Presentation on Android application life cycle and saved instancestatePresentation on Android application life cycle and saved instancestate
Presentation on Android application life cycle and saved instancestate
 
Android Basic Components
Android Basic ComponentsAndroid Basic Components
Android Basic Components
 
Android Components
Android ComponentsAndroid Components
Android Components
 
Ppt 2 android_basics
Ppt 2 android_basicsPpt 2 android_basics
Ppt 2 android_basics
 
Android UI Fundamentals part 1
Android UI Fundamentals part 1Android UI Fundamentals part 1
Android UI Fundamentals part 1
 
Android apps development
Android apps developmentAndroid apps development
Android apps development
 
Event handling in Java(part 2)
Event handling in Java(part 2)Event handling in Java(part 2)
Event handling in Java(part 2)
 
Android intents, notification and broadcast recievers
Android intents, notification and broadcast recieversAndroid intents, notification and broadcast recievers
Android intents, notification and broadcast recievers
 
Android components
Android componentsAndroid components
Android components
 
Android activities & views
Android activities & viewsAndroid activities & views
Android activities & views
 
Day 4: Activity lifecycle
Day 4: Activity lifecycleDay 4: Activity lifecycle
Day 4: Activity lifecycle
 
Event handling in Java(part 1)
Event handling in Java(part 1)Event handling in Java(part 1)
Event handling in Java(part 1)
 
Events and Listeners in Android
Events and Listeners in AndroidEvents and Listeners in Android
Events and Listeners in Android
 
Android Components & Manifest
Android Components & ManifestAndroid Components & Manifest
Android Components & Manifest
 
Android activity
Android activityAndroid activity
Android activity
 
Android
AndroidAndroid
Android
 
Android activity, service, and broadcast recievers
Android activity, service, and broadcast recieversAndroid activity, service, and broadcast recievers
Android activity, service, and broadcast recievers
 
Lab1-android
Lab1-androidLab1-android
Lab1-android
 

Destacado

Destacado (10)

Android intent
Android intentAndroid intent
Android intent
 
Android intents
Android intentsAndroid intents
Android intents
 
Android Lecture #01 @PRO&BSC Inc.
Android Lecture #01 @PRO&BSC Inc.Android Lecture #01 @PRO&BSC Inc.
Android Lecture #01 @PRO&BSC Inc.
 
Level 1 &amp; 2
Level 1 &amp; 2Level 1 &amp; 2
Level 1 &amp; 2
 
Intent in android
Intent in androidIntent in android
Intent in android
 
Android Activity Transition(ShareElement)
Android Activity Transition(ShareElement)Android Activity Transition(ShareElement)
Android Activity Transition(ShareElement)
 
Android: Intent, Intent Filter, Broadcast Receivers
Android: Intent, Intent Filter, Broadcast ReceiversAndroid: Intent, Intent Filter, Broadcast Receivers
Android: Intent, Intent Filter, Broadcast Receivers
 
Android Lesson 3 - Intent
Android Lesson 3 - IntentAndroid Lesson 3 - Intent
Android Lesson 3 - Intent
 
Android - Intents - Mazenet Solution
Android - Intents - Mazenet SolutionAndroid - Intents - Mazenet Solution
Android - Intents - Mazenet Solution
 
Android ppt
Android ppt Android ppt
Android ppt
 

Similar a Intents are Awesome

Mobile Application Development -Lecture 09 & 10.pdf
Mobile Application Development -Lecture 09 & 10.pdfMobile Application Development -Lecture 09 & 10.pdf
Mobile Application Development -Lecture 09 & 10.pdf
AbdullahMunir32
 
android_mod_3.useful for bca students for their last sem
android_mod_3.useful for bca students for their last semandroid_mod_3.useful for bca students for their last sem
android_mod_3.useful for bca students for their last sem
aswinbiju1652
 
Ch5 intent broadcast receivers adapters and internet
Ch5 intent broadcast receivers adapters and internetCh5 intent broadcast receivers adapters and internet
Ch5 intent broadcast receivers adapters and internet
Shih-Hsiang Lin
 
Android webinar class_3
Android webinar class_3Android webinar class_3
Android webinar class_3
Edureka!
 

Similar a Intents are Awesome (20)

Android intents in android application-chapter7
Android intents in android application-chapter7Android intents in android application-chapter7
Android intents in android application-chapter7
 
ANDROID
ANDROIDANDROID
ANDROID
 
Data Transfer between activities and Database
Data Transfer between activities and Database Data Transfer between activities and Database
Data Transfer between activities and Database
 
unit3.pptx
unit3.pptxunit3.pptx
unit3.pptx
 
Mobile Application Development -Lecture 09 & 10.pdf
Mobile Application Development -Lecture 09 & 10.pdfMobile Application Development -Lecture 09 & 10.pdf
Mobile Application Development -Lecture 09 & 10.pdf
 
Data Transfer between Activities & Databases
Data Transfer between Activities & DatabasesData Transfer between Activities & Databases
Data Transfer between Activities & Databases
 
Android - Android Intent Types
Android - Android Intent TypesAndroid - Android Intent Types
Android - Android Intent Types
 
Activity & Shared Preference
Activity & Shared PreferenceActivity & Shared Preference
Activity & Shared Preference
 
android_mod_3.useful for bca students for their last sem
android_mod_3.useful for bca students for their last semandroid_mod_3.useful for bca students for their last sem
android_mod_3.useful for bca students for their last sem
 
Ch5 intent broadcast receivers adapters and internet
Ch5 intent broadcast receivers adapters and internetCh5 intent broadcast receivers adapters and internet
Ch5 intent broadcast receivers adapters and internet
 
Android webinar class_3
Android webinar class_3Android webinar class_3
Android webinar class_3
 
How to integrate flurry in android
How to integrate flurry in androidHow to integrate flurry in android
How to integrate flurry in android
 
MD-IV-CH-ppt.ppt
MD-IV-CH-ppt.pptMD-IV-CH-ppt.ppt
MD-IV-CH-ppt.ppt
 
Hieu Xamarin iOS9, Android M 3-11-2015
Hieu Xamarin iOS9, Android M  3-11-2015Hieu Xamarin iOS9, Android M  3-11-2015
Hieu Xamarin iOS9, Android M 3-11-2015
 
MAD Unit 5.pptxxxxxxxxxxxxxxxxxxxxxxxxxx
MAD Unit 5.pptxxxxxxxxxxxxxxxxxxxxxxxxxxMAD Unit 5.pptxxxxxxxxxxxxxxxxxxxxxxxxxx
MAD Unit 5.pptxxxxxxxxxxxxxxxxxxxxxxxxxx
 
Intent, Service and BroadcastReciver (2).ppt
Intent, Service and BroadcastReciver (2).pptIntent, Service and BroadcastReciver (2).ppt
Intent, Service and BroadcastReciver (2).ppt
 
Tk2323 lecture 3 intent
Tk2323 lecture 3   intentTk2323 lecture 3   intent
Tk2323 lecture 3 intent
 
Android Activities.pdf
Android Activities.pdfAndroid Activities.pdf
Android Activities.pdf
 
Pertemuan 03 - Activities and intents.pptx
Pertemuan 03 - Activities and intents.pptxPertemuan 03 - Activities and intents.pptx
Pertemuan 03 - Activities and intents.pptx
 
Hello android world
Hello android worldHello android world
Hello android world
 

Último

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Último (20)

Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 

Intents are Awesome

  • 1. Israel Ferrer Android Lover since 2008 cofounder bubiloop cofounder android.es Barcelona GTUG Leader Android Dev at Fever Head Mobile Dept. at ASMWS Computer Science at LaSalle
  • 2. INTENTS ARE AWESOME really, trust me! Israel Ferrer 14th March
  • 4. intent |inˈtent| noun intention or purpose: with alarm she realized his intent | a real intent to cut back on social programs. flickr: chinesetealover
  • 5. OK... WHAT DOES THIS REALLY MEAN?
  • 6. Open new Screens Share with other apps Open Camera to take a photo Open file manager Open the browser Open QR Code Scanner ...
  • 8. Explicit Intent Implicit Intent theatricalintelligence
  • 9. EXPLICIT INTENTS • Explicit Intent names the component which should be called by the Android system, using the Java class as identifier. • Used to open new activities in the same app. final Intent intent=new Intent(this, LoginActivity.class); startActivity(intent);
  • 10. IMPLICIT INTENTS • Implicitintent specifies the action to perform and optionally an URI for the action. • Implicit Intent is managed by Android Intent resolution, which maps the intent to a Service, Activity or Broadcasts Receiver • Thisresolution is done by matching intent with intentFilters of every app. • Ifmore than one app can handle the action, the user will have to choose. final Intent intent=new Intent(Intent.ACTION_VIEW, "http://mylookout.com");
  • 11. SHARE DATA • Intents can contain aditional data by using putExtra() method • intent.putExtra(EXTRA_CONVERSATION, conversation); • the receiving component can obtain this data by getExtras() method Bundle extras = getIntent().getExtras(); String conversation = extras.getString(EXTRA_CONVERSATION); if (conversation != null) { // Do something with the data }
  • 12. INTENT FILTERS • AnIntentFilter specifies the types of Intent that an activity, service, or broadcast receiver can respond to. IntentFilters are declared in the Android Manifest. • There are 3 pieces of information used for this resolution: • Action • Type: mymeType or scheme. • Category: need to support DEFAULT to be found by startActivity.
  • 13. INTENT FILTERS Intent final Intent intent=new Intent(Intent.ACTION_VIEW, "http://mylookout.com"); IntentFilter <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>
  • 14. TO SUM UP • Explicit: choose the component to call. • Implicit: isa general intent with action and optionally URI. The Intent resolution call the component that can handle it. • Intents can share data between components and apps.
  • 16. • Reuse code and functionality from 3rd party apps • ACTION_SEND • ACTION_VIEW • geo:lat,lon to open map • http://host to open browser • tel:number to open dialer
  • 17. • Define a set of intents to handle web addresses. • Example: Twitter • Define IntentFilter to handle twitter urls <activity android:name=".UrlHandleActivity" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <data android:host="www.twitter.com" android:scheme="http" /> </intent-filter> </activity>
  • 18. • Check the URL path to fire target Activity public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Uri uri = getIntent().getData(); if (null == uri) { // Shouldn't happen. Handle errors. finish(); return; } String path = uri.getPath(); for (Pair<String, Class> pair : DISPATCH_MAP) { if (path.matches(pair.mFirst)) { Intent intent = new Intent(this, pair.mSecond); intent.setData(uri); startActivity(intent); finish(); return; } } finish(); } private static final List<Pair<String, Class>> DISPATCH_MAP = new LinkedList<Pair<String, Class>>(); static { DISPATCH_MAP.add(new Pair<String, Class>("(.*)/status$", TweetActivity.class)); DISPATCH_MAP.add(new Pair<String, Class>("/another/path", ProfileActivity.class)); }
  • 19. • Exposeintents to 3rd party apps. Example: Lookout public backup intent.
  • 21. A core component of Android. A way to reuse functionality between apps. The glue between activities. The mashup concept into a mobile platform Intents are Awesome for users & developers