Linking Activities using Intents

Slides:



Advertisements
Similar presentations
Programming with Android: Activities and Intents
Advertisements

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.
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.
Mobile Programming Pertemuan 6 Presented by Mulyono Poltek NSC Surabaya.
Intent An Intent describes the operation to be performed. Intents are used to start an activity using either of the following methods – Context.startActivity()
Bluetooth. Bluetooth is an open, wireless protocol for exchanging data between devices over a short distance. –managed by the Bluetooth Special Interest.
 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.
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.
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.
Intent Erick Pranata © Sekolah Tinggi Teknik Surabaya 1.
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.
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.
Intents 1 CS440. Intents  Message passing mechanism  Most common uses:  starting an Activity (open an , contact, etc.)  starting an Activity.
로봇을 조종하자 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
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.
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
Permissions.
Mobile Applications (Android Programming)
Intents and Broadcast Receivers
Lecture 2: Android Concepts
Bluetooth.
several communicating screens
Programming with Android:
Android 5: Interacting with Other Apps
Lecture 7: Android Services
Lecture 3 agenda A tour of Android studio features
CS499 – Mobile Application Development
Android Speech Recognition
Android Introduction Camera.
Android Programming Lecture 5
CIS 470 Mobile App Development
Many thanks to Jun Bum Lim for his help with this tutorial.
Activities and Intents
Android Topics What are Intents? Implicit Intents vs. Explicit Intents
Activities and Intents
Activity & Intent.
CIS 470 Mobile App Development
Objects First with Java
Activities and Intents
It is used to Start an Activity Start a Service Deliver a Broadcast
Lecture 2: Android Concepts
Objects First with Java
Mobile Programming Dr. Mohsin Ali Memon.
Chapter 5 Your Second Activity.
Activities, Fragments, and Intents
CIS 694/EEC 693 Android Sensor Programming
Presentation transcript:

Linking Activities using Intents How to navigate between Android Activities Linking Activities using Intents

Navigation from an Activity to another Activity Create an Intent object Intents can be created in different ways Intents can carry data from the calling Activity to the called Activity Start the other Activity, using the Intent object When the called Activity ends (finish() method) the control is returned to the calling Activity The return of controls can carry data back to the calling activity Comparable to calling a method in Java. You use the keyword return to get back to the calling method. Example: IntentsSimple Linking Activities using Intents

Different ways of creating an Intent object Creating an Intent object linking to an Activity in the same project Intent intent = new Intent(this, Activity2.class) Creating an Intent object linking to an Activity in another project Intent intent = new Intent(”dk.easj.Activity2”); The other project must register the Intent name in the AndroidManifest.xml <activity android:name=".Activity2" <!-- .class name --> android:label="Activity 2"> <intent-filter > <action android:name="dk.easj.Activity2" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity> Linking Activities using Intents

Passing data using an Intent object: Sending data You can pass data from one Activity to another using the Intent object Example: Sending data Intent intent = new Intent(this, AnotherActivity.class); intent.putExtra(“name”, “Anders”); // Generally putExtra(key, value) startActivityForResult(intent, request_Code); Linking Activities using Intents

Passing data using an Intent object: Reading data The receiving Activity can read the data. Example: Reading data from an Intent Intent intent = getIntent(); CharSequence name = intent.getCharSequenceExtra(“name”); // CharSequence is s super-class of String Example: IntentsWithData Linking Activities using Intents

Returning results from an Intent When the called Activity returns to the calling Activity, it can send data (results) startActivity(…) No results startActivityForResult(…) Results expected startActivityForResult(intent, request_Code); Callback method in calling Activity: protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == request_Code) { // which request? Same request_Code as in the startActivityForResult(…) if (resultCode == RESULT_OK) { // or RESULT_CANCELLED final String fullData = data.getData().toString(); … } Example: IndentDataExample Linking Activities using Intents

Making activities look like dialogs With an Intent you go to another Activity. Dialogs on the other hand usually show up on top of another Activity. Activities can look like Dialogs Shown on top of another Activity Example: AndroidManifest.xml <activity android:name=".NameDialogActivity" android:theme="@android:style/Theme.Dialog"> </activity> Linking Activities using Intents

Navigation to a another application using Intents Android has several built-in applications Browser, phone, etc. You can navigate from you Activity to the built-in applications using Intent pairs Common intents https://developer.android.com/guide/components/intents-common.html Linking Activities using Intents

Intent pairs (action, data) Describes what to be done Examples: View an item, Edit an item, etc. Action examples: ACTION_VIEW, ACTION_DIAL, ACTION_PICK Data Describes which ”object” the intent affects http://www.google.com Tel:+4560609528 Geo:38.999,-44.44 Content://contacts Code example Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.amazon.com")); Example: IntentsForBuiltinApps Linking Activities using Intents

Linking Activities using Intents Using Intent Filters If you want other activities to invoke you activity, you must specify some Intent Filters in the AndroidManifest.xml file. Example: Messenger Head First, page 103 Linking Activities using Intents