Programming with Android: Activities and Intents

Slides:



Advertisements
Similar presentations
Programming with Android: SDK install and initial setup Luca Bedogni Marco Di Felice Dipartimento di Scienze dellInformazione Università di Bologna.
Advertisements

Programming with Android: Android for Tablets Luca Bedogni Marco Di Felice Dipartimento di Scienze dellInformazione Università di Bologna.
Programming with Android: Activities
Programming with Android: Network Operations
Programming with Android: Module Overview
Chapter 1 The Study of Body Function Image PowerPoint
10 Copyright © 2005, Oracle. All rights reserved. Reusing Code with Inheritance and Polymorphism.
6 Copyright © 2005, Oracle. All rights reserved. Building Applications with Oracle JDeveloper 10g.
Click to edit Master title style Page - 1 OneSky Teams Step-by-Step Online Corporate Communication Support 2006.
XP New Perspectives on Microsoft Office Word 2003 Tutorial 7 1 Microsoft Office Word 2003 Tutorial 7 – Collaborating With Others and Creating Web Pages.
State of New Jersey Department of Health and Senior Services Patient Safety Reporting System Module 2 – New Event Entry.
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Child Health Reporting System (CHRS) How to Submit VHSS Data
1 Module 6 Session 5 Getting the message across An interactive tutorial.
Integrify 5.0 Tutorial : Creating a New Process
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 10 Arrays and Tile Mapping Starting Out with Games & Graphics.
How To Use Google Forms to Create A Test Quick Easy Self-Graded!! Instant Reports.
ABC Technology Project
© Paradigm Publishing, Inc Access 2010 Level 1 Unit 1Creating Tables and Queries Chapter 2Creating Relationships between Tables.
1 Undirected Breadth First Search F A BCG DE H 2 F A BCG DE H Queue: A get Undiscovered Fringe Finished Active 0 distance from A visit(A)
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 12 – Security Panel Application Introducing.
VOORBLAD.
Programming with Android: Android for Tablets Luca Bedogni Marco Di Felice Dipartimento di Scienze dell’Informazione Università di Bologna.
Programming with Android: System Architecture
1 Breadth First Search s s Undiscovered Discovered Finished Queue: s Top of queue 2 1 Shortest path from s.
 Copyright I/O International, 2013 Visit us at: A Feature Within from Item Class User Friendly Maintenance  Copyright.
© 2012 National Heart Foundation of Australia. Slide 2.
CE881: Mobile and Social Application Programming Simon M. Lucas Quiz, Walkthrough, Exercise, Lifecycles, Intents.
Macromedia Dreamweaver MX 2004 – Design Professional Dreamweaver GETTING STARTED WITH.
25 seconds left…...
PSSA Preparation.
Chapter 11 Creating Framed Layouts Principles of Web Design, 4 th Edition.
A lesson approach © 2011 The McGraw-Hill Companies, Inc. All rights reserved. a lesson approach Microsoft® PowerPoint 2010 © 2011 The McGraw-Hill Companies,
Contract Audit Follow-Up (CAFU) 3.5 Pre-Defined & Ad hoc Reports November 2009 ITCSO Training Academy.
Profile. 1.Open an Internet web browser and type into the web browser address bar. 2.You will see a web page similar to the one on.
User Friendly Item Relationship Maintenance A Family of Enhancements For iSeries 400 DMAS from  Copyright I/O International, 2006, 2007, 2008, 2010 Skip.
Windfall Web Throughout this slide show there will be hyperlinks (highlighted in blue). Follow the hyperlinks to navigate to the specified Topic or Figure.
What’s new in WebSpace Changes and improvements with Xythos 7.2 Effective June 24,
Application Fundamentals Android Development. Announcements Posting in D2L Tutorials.
Programming with Android: Activities and Intents Luca Bedogni Marco Di Felice Dipartimento di Scienze dell’Informazione Università di Bologna.
Programming with Android: Activities and Intents Luca Bedogni Marco Di Felice Dipartimento di Informatica – Scienza e Ingegneria Università di Bologna.
Programming with Android: SDK install and initial setup Luca Bedogni Marco Di Felice Dipartimento di Informatica: Scienza e Ingegneria Università di Bologna.
Programming with Android: Activities
Android 02: Activities David Meredith
Intent An Intent describes the operation to be performed. Intents are used to start an activity using either of the following methods – Context.startActivity()
 Understanding an activity  Starting an activity  Passing information between activities  Understanding intents  Understanding the activity lifecycle.
CS378 - Mobile Computing Intents.
Overview of Android Application Development
CS378 - Mobile Computing Intents. Allow us to use applications and components that are part of Android System – start activities – start services – deliver.
COMP 365 Android Development.  Every android application has a manifest file called AndroidManifest.xml  Found in the Project folder  Contains critical.
Lec 03 Intents Explicit Intents Implicit Intents.
Applications with Multiple Activities. Most applications will have more than one activity. The main activity is started when the application is started.
Working with Multiple Activities. Slide 2 Introduction Working with multiple activities Creating multiple views Introduction to intents Passing data to.
Introducing Intents Intents Bind application components and navigate between them Transform device into collection of interconnected systems Creating a.
Lecture 2: Android Concepts
Activities and Intents Chapter 3 1. Objectives Explore an activity’s lifecycle Learn about saving and restoring an activity Understand intents and how.
Working with Multiple Activities. Slide 2 Introduction Working with multiple activities Putting together the AndroidManifest.xml file Creating multiple.
CS371m - Mobile Computing Intents 1. Allow us to use applications and components that are already part of Android System – start activities – start services.
Android Mobile Application Development
Lecture 2: Android Concepts
Programming with Android:
Activities and Intents
Android Programming Lecture 5
Activities and Intents
HNDIT2417 Mobile Application Development
Activities and Intents
It is used to Start an Activity Start a Service Deliver a Broadcast
Lecture 2: Android Concepts
Presentation transcript:

Programming with Android: Activities and Intents Luca Bedogni Marco Di Felice Dipartimento di Scienze dell’Informazione Università di Bologna 1 1

Outline What is an intent? Intent-field description Handling Explicit Intents Handling implicit Intents Intent-Resolution process Intent with results: Sender side Intent with results: Receiver side 2

More on AndroidManifest.xml Applications should declare everything needed on the the AndroidManifest.xml file … One AndroidManifest.xml for application .. What's contained in it? Permissions Hw and Sw resources used by the Application Activities Intent-filters 3

More on Activities: Activity states Active (or running) Foreground of the screen (top of the stack) Paused Lost focus but still visible Can be killed by the system in extreme situations Stopped Completely obscured by another activity Killed if memory is needed somewhere else 4

More on Activities: Saving resources An activity lifecycle flows between onCreate and onDestroy Create, initialize everything you need in onCreate Destroy everything that is not used anymore, such as background processes, in onDestroy Fundamental to save the data used by the application between state-transitions … 5

Activities and AndroidManifest.xml An Android application can be composed of multiple Activities … Each activity should be declared in the file: AndroidManifest.xml Add a child element of <application>: <application> <activity android:name=".MyActivity" /> <activity android:name=”.SecondActivity" /> </application> 6

AndroidManifest.xml example <?xml version="1.0" encoding="utf-8"?> <manifest> <application android:icon="@drawable/icon.png" > <activity android:name="com.example.project.MyActivity" android:label="@string/label"> </activity> </application> </manifest> 7

Intent Definition Intent: facility for late run-time binding between components in the same or different applications. Call a component from another component Possible to pass data between components Something like: “Android, please do that with this data” Reuse already installed applications Components: Activities, Services, Broadcast receivers … 8

Intent Definition We can think to an “Intent” object as a message containing a bundle of information. Information of interests for the receiver (e.g. data) Information of interests for the Android system (e.g. category). Component Name Action Name Data Structure of an Intent Category Extra Flags 9

Intent Components We can think to an “Intent” object as a message containing a bundle of information. Information of interests for the receiver (e.g. data) Information of interests for the Android system (e.g. category). Component Name Component that should handle the intent (i.e. the receiver). It is optional (implicit intent) void setComponent() Action Name Data Category Extra Flags 10

Intent Components We can think to an “Intent” object as a message containing a bundle of information. Information of interests for the receiver (e.g. data) Information of interests for the Android system (e.g. category). Component Name A string naming the action to be performed. Pre-defined, or can be specified by the programmer. void setAction() Action Name Data Category Extra Flags 11

Intent Components Predefined actions (http://developer.android.com/reference/android/content/Intent.html) Action Name Description ACTION_CALL Initiate a phone call ACTION_EDIT Display data to edit ACTION_MAIN Start as a main entry point, does not expect to receive data. ACTION_PICK Pick an item from the data, returning what was selected. ACTION_VIEW Display the data to the user ACTION_SEARCH Perform a search Defined by the programmer it.example.projectpackage.FILL_DATA (package prefix + name action) 12

Intent Components We can think to an “Intent” object as a message containing a bundle of information. Information of interests for the receiver (e.g. data) Information of interests for the Android system (e.g. category). Component Name Data passed from the caller to the called Component. Location of the data (URI) and Type of the data (MIME type) void setData() Action Name Data Category Extra Flags 13

Intent Components Each data is specified by a name and/or type. name: Uniform Resource Identifier (URI) scheme://host:port/path content://com.example.project:200/folder content://contacts/people content://contacts/people/1 EXAMPLEs 14

Intent Components Each data is specified by a name and/or type. type: MIME (Multipurpose Internet Mail Extensions)-type Composed by two parts: a type and a subtype Image/gif image/jpeg image/png image/tiff text/html text/plain text/javascript text/css video/mp4 video/mpeg4 video/quicktime video/ogg application/vnd.google-earth.kml+xml EXAMPLEs 15

Intent Components We can think to an “Intent” object as a message containing a bundle of information. Information of interests for the receiver (e.g. data) Information of interests for the Android system (e.g. category). A string containing information about the kind of component that should handle the Intent. > 1 can be specified for an Intent void addCategory() Component Name Action Name Data Category Extra Flags 16

Intent Components Category: string describing the kind of component that should handle the intent. Category Name Description CATEGORY_HOME The activity displays the HOME screen. CATEGORY_LAUNCHER The activity is listed in the top-level application launcher, and can be displayed. CATEGORY_PREFERENCE The activity is a preference panel. CATEGORY_BROWSABLE The activity can be invoked by the browser to display data referenced by a link. 17

Intent Components We can think to an “Intent” object as a message containing a bundle of information. Information of interests for the receiver (e.g. data) Information of interests for the Android system (e.g. category). Additional information that should be delivered to the handler(e.g. parameters). Key-value pairs void putExtras() getExtras() Component Name Action Name Data Category Extra Flags 18

Intent Components We can think to an “Intent” object as a message containing a bundle of information. Information of interests for the receiver (e.g. data) Information of interests for the Android system (e.g. category). Component Name Action Name Additional information that instructs Android how to launch an activity, and how to treat it after executed. Data Category Extra Flags 19

Intent types INTENT TYPES IMPLICIT EXPLICIT The target receiver is specified by data type/names. The system chooses the receiver that matches the request. The target receiver is specified through the Component Name Used to launch specific Activities 20

Intent types: Explicit Intents Explicit Intent: Specify the activity that will handle the intent. Intent intent=new Intent(this, SecondActivity.class); startActivity(intent); Intent intent=new Intent(); ComponentName component=new ComponentName(this,SecondActivity.class); intent.setComponent(component); startActivity(intent); 21

Intent types: Implicit Intents Implicit Intents: do not name a target (component name is left blank) … When an Intent is launched, Android checks out which activies could answer to such Intent … If at least one is found, then that activity is started! Binding does not occur at compile time, nor at install time, but at run-time …(late run-time binding) 22

Intent types: Implicit Intents Intent i = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse("http://informatica.unibo.it")); startActivity(i); Action to perform Data to perform the action on Implicit intents are very useful to re-use code and to launch external applications … More than a Component can match the Intent request … How to define the target component? 23

Intent types: Implicit Intents How to declare what intents I'm able to handle? <intent-filter> tag in AndroidManifest.xml How? <intent-filter> <action android:name=”my.project.ACTION_ECHO” /> </intent-filter> If anyone calls an Intent with “my.project.ACTION_ECHO” as action, our activity will be called 24

Intent types: Intent Resolution The intent resolution process resolves the Intent- Filter that can handle a given Intent. Three tests to be passed: Action field test Category field test Data field test If the Intent-filter passes all the three test, then it is selected to handle the Intent. 25

Intent types: Intent Resolution (ACTION Test): The action specified in the Intent must match one of the actions listed in the filter. If the filter does not specify any action  FAIL An intent that does not specify an action  SUCCESS as as long as the filter contains at least one action. <intent-filer … > <action android:name=“com.example.it.ECHO”/> </intent-filter> 26

Intent types: Intent Resolution (CATEGORY Test): Every category in the Intent must match a category of the filter. If the category is not specified in the Intent  Android assumes it is CATEGORY_DEFAULT, thus the filter must include this category to handle the intent <intent-filer … > <category android:name=“android.intent.category.DEFAULT”/> </intent-filter> 27

Intent types: Intent Resolution (DATA Test): The URI of the intent is compared with the parts of the URI mentioned in the filter (this part might be incompleted). <intent-filer … > <data android:mimeType=“audio/* android:scheme=“http”/> <data android:mimeType=“video/mpeg android:scheme=“http”/> </intent-filter> Both URI and MIME-types are compared (4 different sub-cases …) 28

Sender side: invoke the startActivityForResult() Intent with Results Activities could return results ....Useful for calling activities and have some data back! Sender side: invoke the startActivityForResult() onActivityResult(int requestCode, int resultCode, Intent data) startActivityForResult(Intent intent, int requestCode); Intent intent = new Intent(Intent.ACTION_PICK); intent.setData(android.provider.Contacts.People.CONTENT_URI); startActivityForResult(intent,CHOOSE_ACTIVITY_CODE); 29

Receiver side: invoke the setResult() Intent with Results Activities could return results ....Useful for calling activities and have some data back Receiver side: invoke the setResult() void setResult(int resultCode, Intent data) void setResult(int resultCode, Intent data); finish(); The result is delivered to the caller component only after invoking the finish() method! 30