Presentation is loading. Please wait.

Presentation is loading. Please wait.

Android Topics What are Intents? Implicit Intents vs. Explicit Intents

Similar presentations


Presentation on theme: "Android Topics What are Intents? Implicit Intents vs. Explicit Intents"— Presentation transcript:

1 Android Topics What are Intents? Implicit Intents vs. Explicit Intents
What is the content of an Intent message? Practice: In-Class App

2 What are Intents? Most apps require us to send intents
Example: the Coffee Ordering App will require us to send off the order summary in an . The app must launch an app that exists on the device.  An intent is a message that requests some type of action to be performed by another app component. This could be a camera, , Google Maps, or even an activity in another app.

3 Why are Intents Important?
Intents are a powerful part of the Android framework. They allow apps to leverage functionality that other apps provide. They let developers be efficient and smart, because we're not reinventing what other apps already do extremely well.

4 How Intents work Intents are like tossing a ball to someone.
An app component can send an intent to another app or app component. Camera Map

5 Implicit Intents vs. Explicit Intents
There are two types of intents: Implicit and Explicit. An intent can be sent to an explicit app or component. An Intent can be sent implicitly.

6 Implicit Intent An Implicit Intent specifies only the action to be performed. An Implicit Intent does not specify the explicit Android components which should be called. As an analogy, imagine that we need you throw the ball, but we don't have to know who we're throwing it at, as long as there is someone there to catch it. Implicit – doesn’t care who catches it.

7 Implicit Intent Example
Google Maps provides a restaurant listing. Clicking on Website sends an intent to display the restaurant website.

8 Implicit Intent Example Result
Google Maps app does not care which web browser handles the website launch request.  If the user only has one web browser installed on their device, then that app will automatically handle the request. If the user has four web browsers installed on their device, then the Android framework will pop up a window to ask the user to just pick one.

9 Explicit Intent Sometimes we want to be 100% sure that when we send an intent. Perhaps we want a very specific component to receive it. We will discuss this more next week. Explicit– Does care who catches it.

10 What is the content if an Intent message
What is the content if an Intent message? What is contained inside the ball that represents an intent? Think of an intent as a message specifying some operation to be performed. Intents contain two primary elements and possibly extra elements. The general action and Data to act upon. You can also specify additional information such as category, component, and extras, which is literally extra information.

11 Intent message The general action and and the Data to act upon are used by Android to determine which app component can actually handle the intent. TIP: Use Android’s the Common Intents guide for understanding the options when creating intents.

12 Example Intent messages
Map Example An implicit ntent that launches a map would contain the action ACTION_VIEW, and the data would be the latitude and longitude coordinates of the location that we want to see. Any app that is capable of displaying map using latitude and longitude coordinates can be used to handle the request, such as a map application. Phone Calling Example An implicit intent to dial a phone number would require the action ACTION_DIAL and the corresponding data is the telephone number to call. The data format is in the form tel, colon, followed by the number. Example An implicit intent to send an would require the action ACTION_SENDTO and the corresponding data is the address. The data format is in the form

13 What is a URI? URI is a formatted string and is short for uniform resource identifier. This is a standardized way to structure data so that it can be properly processed on the receiving end. Think about it like a mailing address, it follows a structure so that it can be delivered properly. When sending an intent, a URI is needed so that the data can be properly passed to the receiving app component.

14 Experiment : Lab 4 Exercise 1
 Provide a button for the user to access downtown Redlands in Google Maps. Use an implicit intent in the creation of the app.

15 Tasks: Map App Task 1: Locate the longitude and latitude of a place. geo:Latitude,Longitude. Task 2: Research how to create a simple geolocation intent Take some time to experiment with writing code for different intents listed in the Common Intents guide. You can also do a web search for common intents. The documentation has some useful Task 3: Learn how you can to set the data for an intent. Task 4: Learn how you can check to see if the correct component is available on the device.

16 What did you find in your research?
Create a new Intent object and pass it a ACTION_VIEW. When composing our Intent, we will use an official intent action, such ACTION_VIEW or ACTION_SEND, which are defined as constants within the Intent class. Set the data URI to be a certain set of latitude and longitude coordinates. a. Create a URI string. b. URI is set as the data field within this Intent object. To prevent the app from crashing, check to see if the Intent can be handled. If there's no app component on the device that can handle this Intent, then we skip sending the Intent.


Download ppt "Android Topics What are Intents? Implicit Intents vs. Explicit Intents"

Similar presentations


Ads by Google