Mobile Programming Lecture 5 Composite Views, Activities, Intents and Filters.

Slides:



Advertisements
Similar presentations
Programming with Android: Activities
Advertisements

CE881: Mobile and Social Application Programming Simon M. Lucas Quiz, Walkthrough, Exercise, Lifecycles, Intents.
Programming with Android: Activities
Android 02: Activities David Meredith
All About Android Introduction to Android 1. Creating a New App “These aren’t the droids we’re looking for.” Obi-wan Kenobi 1. Bring up Eclipse. 2. Click.
The Android Activity Lifecycle. Slide 2 Introduction Working with the Android logging system Rotation and multiple layouts Understanding the Android activity.
The Activity Class 1.  One application component type  Provides a visual interface for a single screen  Typically supports one thing a user can do,
Application Fundamentals. See: developer.android.com/guide/developing/building/index.html.
Filip Debelić What is it? Android is a mobile operating system (OS) based on the Linux kernel and currently developed by Google Android,
More on User Interface Android Applications. Layouts Linear Layout Relative Layout Table Layout Grid View Tab Layout List View.
@2011 Mihail L. Sichitiu1 Android Introduction Hello Views Part 1.
Cosc 4730 Android TabActivity and ListView. TabActivity A TabActivity allows for multiple “tabs”. – Each Tab is it’s own activity and the “root” activity.
Chien-Chung Shen Manifest and Activity Chien-Chung Shen
CS378 - Mobile Computing Anatomy of an Android App and the App Lifecycle.
Introduction to Android Programming Content Basic environmental structure Building a simple app Debugging.
 Understanding an activity  Starting an activity  Passing information between activities  Understanding intents  Understanding the activity lifecycle.
ANDROID UI – FRAGMENTS. Fragment  An activity is a container for views  When you have a larger screen device than a phone –like a tablet it can look.
Chapter 9: Customize! Navigating with Tabs on a Tablet App.
Android Mobile computing for the rest of us.* *Prepare to be sued by Apple.
Mobile Computing Lecture#08 IntentFilters & BroadcastReceivers.
Chapter 2: Simplify! The Android User Interface
ANDROID – INTERFACE AND LAYOUT L. Grewe. Interfaces: Two Alternatives Code or XML  You have two ways you can create the interface(s) of your Application.
Mobile Programming Lecture 6
1 Announcements Homework #2 due Feb 7 at 1:30pm Submit the entire Eclipse project in Blackboard Please fill out the when2meets when your Project Manager.
Frank Xu Gannon University.  Linear Layout  Relative Layout  Table Layout.
Activities and Intents. Activities Activity is a window that contains the user interface of your application,typically an application has one or more.
Copyright© Jeffrey Jongko, Ateneo de Manila University Of Activities, Intents and Applications.
1/29/ Android Programming: FrameLayout By Dr. Ramji M. Makwana Professor and Head, Computer Engineering Department A.D. Patel.
Chapter 2 The Android User Interface. Objectives  In this chapter, you learn to:  Develop a user interface using the TextView, ImageView, and Button.
Understand applications and their components activity service broadcast receiver content provider intent AndroidManifest.xml.
User Interfaces: Part 1 (View Groups and Layouts).
Android – Fragments L. Grewe.
Android Boot Camp for Developers Using Java, Comprehensive: A Guide to Creating Your First Android Apps Chapter 2: Simplify! The Android User Interface.
Cosc 4730 Android Fragments. Fragments You can think of a fragment as a modular section of an activity, which has its own lifecycle, receives its own.
ANDROID – DRAWING IMAGES – SIMPLE EXAMPLE IN INTERFACE AND EVENT HANDLING L. Grewe.
Android Using Menus Notes are based on: The Busy Coder's Guide to Android Development by Mark L. Murphy Copyright © CommonsWare, LLC. ISBN:
Mobile Programming Midterm Review
Applications with Multiple Activities. Most applications will have more than one activity. The main activity is started when the application is started.
HW#9 Clues CSCI 571 Fall, HW#9 Prototype
Recap of Part 1 Terminology Windows FormsAndroidMVP FormActivityView? ControlViewView? ?ServiceModel? Activities Views / ViewGroups Intents Services.
CS378 - Mobile Computing User Interface Basics. User Interface Elements View – Control – ViewGroup Layout Widget (Compound Control) Many pre built Views.
Activities and Intents Chapter 3 1. Objectives Explore an activity’s lifecycle Learn about saving and restoring an activity Understand intents and how.
Mobile Programming Lecture 4 Resources, Selection, Activities, Intents.
ANDROID LAYOUTS AND WIDGETS. Slide 2 Introduction Parts of the Android screen Sizing widgets and fonts Layouts and their characteristics Buttons, checkboxes.
School of Engineering and Information and Communication Technology KIT305/KIT607 Mobile Application Development Android OS –Permissions (cont.), Fragments,
Working with Multiple Activities. Slide 2 Introduction Working with multiple activities Putting together the AndroidManifest.xml file Creating multiple.
Chapter 2: Simplify! The Android User Interface
Lab7 – Appendix.
Introduction to android
Android Programming - Features
Mobile Application Development BSCS-7 Lecture # 2
Activity and Fragment.
GUI Programming Fundamentals
Activities, Fragments, and Events
CS499 – Mobile Application Development
Activities and Intents
Android Introduction Hello Views Part 1.
The Android Activity Lifecycle
ANDROID UI – FRAGMENTS UNIT II.
CIS 470 Mobile App Development
Activities and Intents
Activities and Intents
HNDIT2417 Mobile Application Development
CIS 470 Mobile App Development
Activities and Intents
SE4S701 Mobile Application Development
Activities and Fragments
ITEC535 – Mobile Programming
Activities, Fragments, and Intents
CIS 694/EEC 693 Android Sensor Programming
Presentation transcript:

Mobile Programming Lecture 5 Composite Views, Activities, Intents and Filters

Lecture 4 Review How do you get the value of a string in the strings.xml file? What are the steps to populate a Spinner or ListView using XML? How many Android application components are there? Name one. How do you launch an Activity B from within Activity A?

Agenda ViewFlipper SlidingDrawer TabLayout Activity LifeCycle Configuration Changes URI Intent Filters

ViewFlipper A ViewFlipper allows you to switch between views that are children of the ViewFlipper You can find it in the Transitions menu in Graphical Layout

ViewFlipper <ViewFlipper android:layout_width="match_parent" android:layout_height="match_parent" > <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" > <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" >

ViewFlipper <ViewFlipper android:layout_width="match_parent" android:layout_height="match_parent" > <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" > <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" > Here I used RelativeLayouts, but you can place any widget you want in here.

ViewFlipper <ViewFlipper android:layout_width="match_parent" android:layout_height="match_parent" > <TextView android:layout_width="match_parent" android:layout_height=“wrap_content" /> <TextView android:layout_width="match_parent" android:layout_height=“match_parent“ / > Here I also used just 2 Views. You can add more than just 2 Views if you want to.

ViewFlipper ViewFlipper public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); flipper = (ViewFlipper) findViewById(R.id.viewFlipper1); flipper.setFlipInterval(500); flipper.startFlipping(); }

ViewFlipper ViewFlipper public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); flipper = (ViewFlipper) findViewById(R.id.viewFlipper1); flipper.setFlipInterval(500); flipper.startFlipping(); } Here we set the flipper to flip every 500 milliseconds

ViewFlipper ViewFlipper public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); flipper.setOnClickListener(new OnClickListener() public void onClick(View v) { flipper.showNext(); } }); } Here we set the flipper to flip when the flipper is clicked

FrameLayout is designed to block out an area on the screen to display a single item. FrameLayout should be used to hold a single child view o it can be difficult to organize child views in a way that's scalable to different screen sizes without the children overlapping each other FrameLayout

Example: FrameLayout

SlidingDrawer hides content out of the screen and allows the user to drag a handle to bring the content on screen can be used vertically or horizontally composed of two children views o the handle, that the users drags o the content, attached to the handle and dragged with it. should only be used inside of a FrameLayout or a RelativeLayout

SlidingDrawer Note: the android:handle and android:content attributes There needs to be children with id's matching these attributes

android:handle android:content android:orientation o "vertical" or "horizontal" android:allowSingleTap o "true" or "false" o allow the user to open the drawer by tapping on the handle? SlidingDrawer - useful attributes

open() close() setOnDrawerScrollListener(OnDrawerScrollListener) setOnDrawOpenListener(OnDrawerOpenListener) setOnDrawerCloseListener(OnDrawerCloseListener) SlidingDrawer - useful methods

It is used to wrap multiple activities into a single window navigate through the activities using tabs TabLayout

TabLayout - Anatomy TABHOST TABWIDGET ACTIVITY FRAMELAYOUT TAB CONTENT TabHost o container holding TabWidget and a FrameLayout TabWidget o row of tab buttons FrameLayout o container holding the tab contents o each tab content is a child of FrameLayout

TabLayout - XML <TabHost xmlns:android=" android:layout_width="fill_parent" android:layout_height="fill_parent"> <LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TabWidget android:layout_width="fill_parent" android:layout_height="wrap_content" /> <FrameLayout android:layout_width="fill_parent" android:layout_height="fill_parent" /> TABHOST TABWIDGET ACTIVITY FRAMELAYOUT TAB CONTENT

TabLayout - XML <TabHost xmlns:android=" android:layout_width="fill_parent" android:layout_height="fill_parent"> <LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TabWidget android:layout_width="fill_parent" android:layout_height="wrap_content" /> <FrameLayout android:layout_width="fill_parent" android:layout_height="fill_parent" /> TABHOST TABWIDGET ACTIVITY FRAMELAYOUT TAB CONTENT Tabs are different Activities, we can set and specify the layout for each tab programmatically

TabLayout If you're going to have x number of tabs, create x number of Activities, 1 for each tab, in addition to the TabActivity (Host Activity). You can create x number of XML layouts for each tab, or you can reuse the same layout for each tab.

TabLayout public class TabLayoutExampleActivity extends TabActivity public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); TabHost tabHost = getTabHost(); // The activity TabHost TabHost.TabSpec spec; Intent intent = new Intent(TabLayoutExampleActivity.this, LinearLayout.class); spec = tabHost.newTabSpec("linear layout").setIndicator("Linear", null).setContent(intent); tabHost.addTab(spec); intent = new Intent(TabLayoutExampleActivity.this, TableLayout.class); spec = tabHost.newTabSpec("table layout").setIndicator("Table",null).setContent(intent); tabHost.addTab(spec); }

TabLayout public class TabLayoutExampleActivity extends TabActivity public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); TabHost tabHost = getTabHost(); // The activity TabHost TabHost.TabSpec spec; Intent intent = new Intent(TabLayoutExampleActivity.this, LinearLayout.class); spec = tabHost.newTabSpec("linear layout").setIndicator("Linear", null).setContent(intent); tabHost.addTab(spec); intent = new Intent(TabLayoutExampleActivity.this, TableLayout.class); spec = tabHost.newTabSpec("table layout").setIndicator("Table",null).setContent(intent); tabHost.addTab(spec); } extend TabActivity

TabLayout public class TabLayoutExampleActivity extends TabActivity public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); TabHost tabHost = getTabHost(); // The activity TabHost TabHost.TabSpec spec; Intent intent = new Intent(TabLayoutExampleActivity.this, LinearLayout.class); spec = tabHost.newTabSpec("linear layout").setIndicator("Linear", null).setContent(intent); tabHost.addTab(spec); intent = new Intent(TabLayoutExampleActivity.this, TableLayout.class); spec = tabHost.newTabSpec("table layout").setIndicator("Table",null).setContent(intent); tabHost.addTab(spec); } the XML file containing the TabHost, TabWidget, FrameLayout

TabLayout public class TabLayoutExampleActivity extends TabActivity public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); TabHost tabHost = getTabHost(); TabHost.TabSpec spec; Intent intent = new Intent(TabLayoutExampleActivity.this, LinearLayout.class); spec = tabHost.newTabSpec("linear layout").setIndicator("Linear", null).setContent(intent); tabHost.addTab(spec); intent = new Intent(TabLayoutExampleActivity.this, TableLayout.class); spec = tabHost.newTabSpec("table layout").setIndicator("Table",null).setContent(intent); tabHost.addTab(spec); } Reference to the Activity's TabHost (which was defined in XML)

TabLayout public class TabLayoutExampleActivity extends TabActivity public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); TabHost tabHost = getTabHost(); TabHost.TabSpec spec; Intent intent = new Intent(TabLayoutExampleActivity.this, LinearLayout.class); spec = tabHost.newTabSpec("linear layout").setIndicator("Linear", null).setContent(intent); tabHost.addTab(spec); intent = new Intent(TabLayoutExampleActivity.this, TableLayout.class); spec = tabHost.newTabSpec("table layout").setIndicator("Table",null).setContent(intent); tabHost.addTab(spec); } Reusable TabSpec for each Tab.

TabLayout public class TabLayoutExampleActivity extends TabActivity public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); TabHost tabHost = getTabHost(); TabHost.TabSpec spec; Intent intent = new Intent(TabLayoutExampleActivity.this, LinearLayout.class); spec = tabHost.newTabSpec("linear layout").setIndicator("Linear", null).setContent(intent); tabHost.addTab(spec); intent = new Intent(TabLayoutExampleActivity.this, TableLayout.class); spec = tabHost.newTabSpec("table layout").setIndicator("Table",null).setContent(intent); tabHost.addTab(spec); } The TabSpec tells the TabHost what views represent the tab contents and what the tab buttons should look like.

TabLayout public class TabLayoutExampleActivity extends TabActivity public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); TabHost tabHost = getTabHost(); TabHost.TabSpec spec; Intent intent = new Intent(TabLayoutExampleActivity.this, LinearLayout.class); spec = tabHost.newTabSpec("linear layout").setIndicator("Linear", null).setContent(intent); tabHost.addTab(spec); Intent intent = new Intent(TabLayoutExampleActivity.this, TableLayout.class); spec = tabHost.newTabSpec("table layout").setIndicator("Table",null).setContent(intent); tabHost.addTab(spec); } Remember from the previous lecture, this is how we use an Intent object to start another Activity

TabLayout public class TabLayoutExampleActivity extends TabActivity public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); TabHost tabHost = getTabHost(); TabHost.TabSpec spec; Intent intent = new Intent(TabLayoutExampleActivity.this, LinearLayout.class); spec = tabHost.newTabSpec("linear layout").setIndicator("Linear", null).setContent(intent); tabHost.addTab(spec); Intent intent = new Intent(TabLayoutExampleActivity.this, TableLayout.class); spec = tabHost.newTabSpec("table layout").setIndicator("Table",null).setContent(intent); tabHost.addTab(spec); } Refer to this TabActivity's tab host (which will contain the actual tabs)

TabLayout public class TabLayoutExampleActivity extends TabActivity public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); TabHost tabHost = getTabHost(); TabHost.TabSpec spec; Intent intent = new Intent(TabLayoutExampleActivity.this, LinearLayout.class); spec = tabHost.newTabSpec("linear layout").setIndicator("Linear", null).setContent(intent); tabHost.addTab(spec); Intent intent = new Intent(TabLayoutExampleActivity.this, TableLayout.class); spec = tabHost.newTabSpec("table layout").setIndicator("Table",null).setContent(intent); tabHost.addTab(spec); } Create a new tab spec, give it the id "linear layout"

TabLayout public class TabLayoutExampleActivity extends TabActivity public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); TabHost tabHost = getTabHost(); TabHost.TabSpec spec; Intent intent = new Intent(TabLayoutExampleActivity.this, LinearLayout.class); spec = tabHost.newTabSpec("linear layout").setIndicator("Linear", null).setContent(intent); tabHost.addTab(spec); Intent intent = new Intent(TabLayoutExampleActivity.this, TableLayout.class); spec = tabHost.newTabSpec("table layout").setIndicator("Table",null).setContent(intent); tabHost.addTab(spec); } Set the label for the tab (label the user sees) to "Linear". And

TabLayout public class TabLayoutExampleActivity extends TabActivity public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); TabHost tabHost = getTabHost(); TabHost.TabSpec spec; Intent intent = new Intent(TabLayoutExampleActivity.this, LinearLayout.class); spec = tabHost.newTabSpec("linear layout").setIndicator("Linear", null).setContent(intent); tabHost.addTab(spec); Intent intent = new Intent(TabLayoutExampleActivity.this, TableLayout.class); spec = tabHost.newTabSpec("table layout").setIndicator("Table",null).setContent(intent); tabHost.addTab(spec); } We're not using an image for the tabs, so null for this argument

TabLayout public class TabLayoutExampleActivity extends TabActivity public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); TabHost tabHost = getTabHost(); TabHost.TabSpec spec; Intent intent = new Intent(TabLayoutExampleActivity.this, LinearLayout.class); spec = tabHost.newTabSpec("linear layout").setIndicator("Linear", null).setContent(intent); tabHost.addTab(spec); Intent intent = new Intent(TabLayoutExampleActivity.this, TableLayout.class); spec = tabHost.newTabSpec("table layout").setIndicator("Table",null).setContent(intent); tabHost.addTab(spec); } Fill the FrameLayout to hold the Activity specified by this intent

TabLayout public class TabLayoutExampleActivity extends TabActivity public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); TabHost tabHost = getTabHost(); TabHost.TabSpec spec; Intent intent = new Intent(TabLayoutExampleActivity.this, LinearLayout.class); spec = tabHost.newTabSpec("linear layout").setIndicator("Linear", null).setContent(intent); tabHost.addTab(spec); Intent intent = new Intent(TabLayoutExampleActivity.this, TableLayout.class); spec = tabHost.newTabSpec("table layout").setIndicator("Table",null).setContent(intent); tabHost.addTab(spec); } Add the tab to the tabHost, it will now show up in the UI

TabLayout public class TabLayoutExampleActivity extends TabActivity public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); TabHost tabHost = getTabHost(); TabHost.TabSpec spec; Intent intent = new Intent(TabLayoutExampleActivity.this, LinearLayout.class); spec = tabHost.newTabSpec("linear layout").setIndicator("Linear", null).setContent(intent); tabHost.addTab(spec); Intent intent = new Intent(TabLayoutExampleActivity.this, TableLayout.class); spec = tabHost.newTabSpec("table layout").setIndicator("Table",null).setContent(intent); tabHost.addTab(spec); } To add another tab, let's do this all over again!

TabLayout - Rules — TabHost must have the — The TabWidget must have the id — The FrameLayout must have the id

TabHost - useful methods setCurrentTab(int) o make this tab the active tab, making it visible in the UI setOnTabChangedListener(OnTabChangedListener) o react to when the active tab changes

Activity LifeCycle During the life of an activity, the system calls a core set of lifecycle methods in a sequence. Implementing your activity lifecycle methods properly ensures your app behaves gracefully in many ways, including that it: o Does not crash if the user receives a phone call or switches to another app while using your app. o Does not consume valuable system resources when the user is not actively using it. o Does not lose the user's progress if they leave your app and return to it at a later time.

Activity Lifecycle A nice picture of activity lifecycle d/app/Activity.html

Activity LifeCycle - onCreate() Called when the activity is first created. this is where you should do all of your normal static set up: create views, bind data to lists, etc. provides you with a Bundle containing the activity's previously frozen state, if there was one. always followed by onStart().

Activity LifeCycle - onStart() called when the activity is becoming visible to the user followed by o onResume() if the activity comes to the foreground

Activity LifeCycle - onRestart() called after your activity has been stopped, prior to it being started again always followed by onStart()

called when the activity will start interacting with the user at this point your activity is at the top of the activity stack, with user input going to it Always followed by onPause() Activity LifeCycle - onResume()

called when the system is about to start resuming a previous activity this is typically used to commit unsaved changes to persistent data, stop animations and other things that may be consuming CPU, etc implementations of this method must be very quick because the next activity will not be resumed until this method returns followed by o onResume() if the activity returns back to the front o onStop() if it becomes invisible to the user. Activity LifeCycle - onPause()

called when the activity is no longer visible to the user because another activity has been resumed and is covering this one this may happen either because a new activity is being started, an existing one is being brought in front of this one, or this one is being destroyed followed by o onRestart() if this activity is coming back to interact with the user o onDestroy() if this activity is going away Activity LifeCycle - onStop()

the final call you receive before your activity is destroyed this can happen either because o the activity is finishing (someone called finish() ) o the system is temporarily destroying this instance of the activity due to low memory you can distinguish between these two scenarios with the isFinishing() method Activity LifeCycle - onDestroy()

Reading Assignment Please read page 0 – 710 by next class. Pay more attention on the section of Large- Screen Strategies and Tactics. We are going to talk about Fragment next week.

Configuration Changes In your app, you can detect when the configuration of the device changes o screen orientation, keyboard availability, and language In default, the system will try to handle the changes for you, unless you specify that you want to handle them yourself

Configuration Changes - Manifest to specify that, you want to handle orientation and keyboard availability changes by yourself open the manifest file and add the bold line <activity android:configChanges="orientation|keyboardHidden" android:name=".OnConfigurationChangedExampleActivity" >

Configuration Changes - Manifest This specifies one or more configuration changes that the activity will handle itself when the orientation changes and when keyboard availability changes. <activity android:configChanges="orientation|keyboardHidden" android:name=".OnConfigurationChangedExampleActivity" >

Configuration Changes - Event Then, to react to the orientation change event, add this method to your public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) { /*... */ } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) { /*... */ }

Passing Data between Activities When you start Activity B from Activity A, you may want to send data to Activity B Activity AActivity B startActivity B send some data to B also

Passing Data between Activities Activity A - onCreate() Intent intent = new Intent(this, SecondActivity.class); Bundle bundle = new Bundle(); bundle.putString("fname","John"); bundle.putString("lname", "Doe"); bundle.putInt("age", 18); intent.putExtras(bundle); startActivity(intent); Activity B - onCreate() Intent intent = getIntent(); Bundle bundle = intent.getExtras(); if(bundle != null) { edit1.setText(bundle.getString("fname ")); edit2.setText(bundle.getString("lname ")); int age= bundle.getInt("age"); }

Explicit Intent vs Implicit Intent An Intent encapsulates a request, made to Android, for some activity or other receiver to do something. If the activity you intend to launch is one of your own, you may find it simplest to create an explicit Intent. o new Intent(this, MyListViewActivity.class); You can also start up activities from the operating system or third-party apps using implicit intent. o Implicit intent works a lot like the Web HTTP.

Implicit Intent o Action + URI (“data”) o these are almost exactly analogous to HTTP verbs (POST, GET) and URLs — the action is the verb, and the “ data” is a Uri, such as android.intent.action: o MAIN o MUSIC_PLAYER o VIEW o WEB_SEARCH

URIs Uniform Resource Identifier that identifies an abstract or physical resource, as specified by RFC 2396.RFC 2396 The URI class can both parse URI strings into parts and compose URI strings from parts. There are 4 main parts to a URI o Scheme, port, host, and path ml

URIs - Examples - Hierarchical file:///tmp/android.txt schemehostportpath httpmobile.cs.fsu.edu80android httptwitter.com file/tmp/android.txt

URIs - Examples - Opaque mailto:robots.example.com schemescheme-specific part mailtorobots.example.com

URIs - Parsing URIs URI uri = Uri.parse(" String scheme = uri.getScheme(); String host = uri.getHost(); int port = uri.getPort(); String path = uri.getPath(); String schemeSpecificPart = uri.getSchemeSpecificPart();

Intent Filters To inform the system which implicit intents they can handle, activities, services, and broadcast receivers can have one or more intent filters each filter describes a capability of the component, a set of intents that the component is willing to receive it filters in intents of a desired type, while filtering out unwanted intents — but only unwanted implicit intents (those that don't name a target class)

Intent Filters explicit intent o always delivered to its target, no matter what it contains; the filter is not consulted implicit intent o delivered to a component only if it can pass through one of the component's filters

Intent Filters explicit intent o always delivered to its target, no matter what it contains; the filter is not consulted implicit intent o delivered to a component only if it can pass through one of the component's filters We have seen this before! new Intent(A.this, B.class)

Intent Filters How does Android know that you may want to open the YouTube app when you try to watch a video on YouTube? Using Intent Filters We will create an app that can be used to launch links at o

Intent Filters <activity android:name=".MyActivity" > <data android:scheme="http" android:host="mobile.cs.fsu.edu" />

Intent Filters <activity android:name=".MyActivity" > <data android:scheme="http" android:host="mobile.cs.fsu.edu" />

Intent Filters <activity android:name=".MyActivity" > <data android:scheme="http" android:host="mobile.cs.fsu.edu" />

Intent Filters <activity android:name=".MyActivity" > <data android:scheme="http" android:host="mobile.cs.fsu.edu" /> Display data to the user. Generic action you can use on a piece of data to get the most reasonable thing to occur

Intent Filters <activity android:name=".MyActivity" > <data android:scheme="http" android:host="mobile.cs.fsu.edu" /> Set if the Activity should be an option for the default action on a piece of data.

Intent Filters <activity android:name=".MyActivity" > <data android:scheme="http" android:host="mobile.cs.fsu.edu" /> Activities that can be safely invoked from a browser must support this category. It's required here.

Intent Filters <activity android:name=".MyActivity" > <data android:scheme="http" android:host="mobile.cs.fsu.edu" /> This is an Implicit Intent!

References The Busy Coder's Guide to Android Development - Mark Murphy The Busy Coder's Guide to Android Development - Mark Murphy Android Developers The Mobile Lab at Florida State University