Intents 1 CS440. Intents  Message passing mechanism  Most common uses:  starting an Activity (open an email, contact, etc.)  starting an Activity.

Slides:



Advertisements
Similar presentations
Programming with Android: Activities and Intents
Advertisements

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.
Android 02: Activities David Meredith
Intents.
Manifest File, Intents, and Multiple Activities. Manifest File.
The Activity Class 1.  One application component type  Provides a visual interface for a single screen  Typically supports one thing a user can do,
Cosc 5/4730 Android Content Providers and Intents.
Cosc 4/5730 Android Text to Speech And Speech To Text.
@2011 Mihail L. Sichitiu1 Android Introduction Communication between Activities.
Intent An Intent describes the operation to be performed. Intents are used to start an activity using either of the following methods – Context.startActivity()
INTERNATIONAL SUMMER ACADEMIC COURSE UNIVESITY OF NIS ISAC – Android programming.
Lecture 3 agenda Layouts Intents (both explicit and implicit) ListViews and Adapters.
Getting Started with Android APIs Ivan Wong. Motivation - “Datasheet” - Recently exposed to what’s available in Android - So let’s see what API’s are.
 Understanding an activity  Starting an activity  Passing information between activities  Understanding intents  Understanding the activity lifecycle.
Mobile Programming Lecture 9 Bound Service, Location, Sensors, IntentFilter.
CSS216 MOBILE PROGRAMMING Android, Chapter 5 Book: “Professional Android™ 2 Application Development” by Reto Meier, 2010 by: Andrey Bogdanchikov (
Intent Android Club Agenda Intent class Explicit activation Implicit activation.
CS378 - Mobile Computing Intents.
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.
1 Mobile Software Development Framework: Android 2/28/2011 Y. Richard Yang.
CS378 - Mobile Computing Intents. Allow us to use applications and components that are part of Android System – start activities – start services – deliver.
Android Development 1 Yuliana Setiowati Rizky Yuniar Hakkun Ahmad Syauqi Ahsan.
Lec 03 Intents Explicit Intents Implicit Intents.
Cosc 5/4730 Android Communications Intents, callbacks, and setters.
Linking Activities using Intents How to navigate between Android Activities 1Linking Activities using Intents.
Activity Android Club Agenda Hello Android application Application components Activity StartActivity.
Mobile Programming Midterm Review
1 CMSC 628: Introduction to Mobile Computing Nilanjan Banerjee Introduction to Mobile Computing University of Maryland Baltimore County
Applications with Multiple Activities. Most applications will have more than one activity. The main activity is started when the application is started.
1 Mobile Software Development Framework: Android Inter- Thread, Process Communications 10/11/2012 Y. Richard Yang.
Working with Multiple Activities. Slide 2 Introduction Working with multiple activities Creating multiple views Introduction to intents Passing data to.
Lec 04 Intents and Bundles Fragments. Activated by Intents Activities Services Broadcast Receivers (aka Receivers) (
Introducing Intents Intents Bind application components and navigate between them Transform device into collection of interconnected systems Creating a.
Activities and Intents Richard S. Stansbury 2015.
로봇을 조종하자 4/4 UNIT 18 로봇 SW 콘텐츠 교육원 조용수. 학습 목표 Intent Activity 호출 2.
Android Intents Nasrullah. Using the application context You use the application context to access settings and resources shared across multiple activity.
Lecture 2: Android Concepts
Cosc 5/4735 Voice Actions Voice Interactions (API 23+)
Technische Universität München Services, IPC and RPC Gökhan Yilmaz, Benedikt Brück.
Activities and Intents Chapter 3 1. Objectives Explore an activity’s lifecycle Learn about saving and restoring an activity Understand intents and how.
Intents and Broadcast Receivers Dr. David Janzen Except as otherwise noted, the content of this presentation is licensed under the Creative Commons Attribution.
David Sutton SMS TELEPHONY IN ANDROID. OUTLINE  This week’s exercise, an SMS Pub Quiz  Simulating telephony on an emulator  Broadcast Intents and broadcast.
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
Intents and Broadcast Receivers
Lecture 2: Android Concepts
several communicating screens
Programming with Android:
Android 5: Interacting with Other Apps
Linking Activities using Intents
Lecture 3 agenda A tour of Android studio features
Communication between Activities
Android Speech Recognition
Android Introduction Camera.
Android Programming Lecture 5
CIS 470 Mobile App Development
Activities and Intents
Android Topics What are Intents? Implicit Intents vs. Explicit Intents
Activities and Intents
CIS 470 Mobile App Development
Objects First with Java
Activities and Intents
Lecture 2: Android Concepts
Objects First with Java
Mobile Programming Dr. Mohsin Ali Memon.
Activities and Fragments
CIS 694/EEC 693 Android Sensor Programming
CA16R405 - Mobile Application Development (Theory)
Presentation transcript:

Intents 1 CS440

Intents  Message passing mechanism  Most common uses:  starting an Activity (open an , contact, etc.)  starting an Activity for a result (scan a barcode, take a picture to attach to an , etc.) CS440 2

Intents  Explicit Intent i = new Intent(this, ActivityTwo.class); i.putExtra("Value1", "This value one for ActivityTwo "); i.putExtra("Value2", "This value two ActivityTwo");  Implicit Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(" startActivity(i); CS440 3

Example: Share Intent  Sender Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.putExtra(android.content.Intent.EXTRA_TEXT, "News for you!"); startActivity(intent);  Receiver Bundle extras = getIntent().getExtras(); if (extras == null) { return; } // Get data via the key String value1 = extras.getString(Intent.EXTRA_TEXT); if (value1 != null) { // Do something with the data } CS440 4

Calling Sub-Activities for result data  If you need some information from the called Activity use the startActivityForResult() method. public void onClick(View view) { Intent i = new Intent(this, ActivityTwo.class); i.putExtra("Value1", "This value one for ActivityTwo "); i.putExtra("Value2", "This value two ActivityTwo"); // Set the request code to any code you like, you can identify the // callback via this code startActivityForResult(i, REQUEST_CODE); } CS440 5

Calling Sub-Activities for result data  If you use the startActivityForResult() method then the started Activity is called a Sub-Activity.  If the Sub-Activity is finished it can send data back to its caller via Intent. This is done in the finish() public void finish() { // Prepare data intent Intent data = new Intent(); data.putExtra("returnKey1", "Swinging on a star. "); data.putExtra("returnKey2", "You could be better then you are. "); // Activity finished ok, return the data setResult(RESULT_OK, data); super.finish(); } CS440 6

Calling Sub-Activities for result data  Once the Sub-Activity finished, the onActivityResult() method in the calling Activity will be protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == RESULT_OK && requestCode == REQUEST_CODE) { if (data.hasExtra("returnKey1")) { Toast.makeText(this, data.getExtras().getString("returnKey1"), Toast.LENGTH_SHORT).show(); } CS440 7

Intents  Intents use action strings and URIs:  Action Strings Example: ACTION_VIEW content://contacts/people/1 -- Display information about the person whose identifier is "1“ ACTION_VIEW ACTION_DIAL content://contacts/people/1 -- Display the phone dialer with the person filled in. ACTION_DIAL ACTION_DIAL tel: Display the phone dialer with the given number filled in. ACTION_DIAL  URI Example: Search Google Maps: geo:0,0?q=query Show contacts: content://contacts/people Show a URL: CS440 8

Intent Fun  Create a new Project: IntentFun  Create an intent that has data one of the following URIs:   content://contacts/people  geo:0,0?q=query  Do not forget to start an Activity for this intent! CS440 9

Intent Fun  Create an intent that takes a picture:  Use: "android.media.action.IMAGE_CAPTURE“ as an argument in the intent  Start an activity that is based on the result of the intent  Do not forget: you need to override the onActivityResult method… why? CS440 10

Intent Fun  Create a Toast with text “lalala”:  What is a Toast class?  Make the text appear on your screen  Check the open intents registry:  CS440 11

References  recipes.html recipes.html  CS440 12