Application Fundamentals

Similar documents
Minds-on: Android. Session 2

CS 528 Mobile and Ubiquitous Computing Lecture 3b: Android Activity Lifecycle and Intents Emmanuel Agu

Android Fundamentals - Part 1

CS378 - Mobile Computing. Anatomy of an Android App and the App Lifecycle

CS 4518 Mobile and Ubiquitous Computing Lecture 5: Rotating Device, Saving Data, Intents and Fragments Emmanuel Agu

Understand applications and their components. activity service broadcast receiver content provider intent AndroidManifest.xml

application components

Android Activities. Akhilesh Tyagi

University of Babylon - College of IT SW Dep. - Android Assist. Lect. Wadhah R. Baiee Activities

Lecture 2 Android SDK

CS378 -Mobile Computing. Anatomy of and Android App and the App Lifecycle

ACTIVITY, FRAGMENT, NAVIGATION. Roberto Beraldi

ANDROID APPS DEVELOPMENT FOR MOBILE AND TABLET DEVICE (LEVEL I)

Mobile Computing. Introduction to Android

COSC 3P97 Mobile Computing

Introduction What is Android?

Activities and Fragments

ANDROID APPS DEVELOPMENT FOR MOBILE AND TABLET DEVICE (LEVEL I)

CS378 -Mobile Computing. Services and Broadcast Receivers

LECTURE NOTES OF APPLICATION ACTIVITIES

Understanding Application

Lab 1: Getting Started With Android Programming

Mobile Application Development Android

CS 4518 Mobile and Ubiquitous Computing Lecture 4: Data-Driven Views, Android Components & Android Activity Lifecycle Emmanuel Agu

Produced by. Mobile Application Development. David Drohan Department of Computing & Mathematics Waterford Institute of Technology

Activities. Repo:

CS 370 Android Basics D R. M I C H A E L J. R E A L E F A L L

Overview of Activities

Android Ecosystem and. Revised v4presenter. What s New

Mobile Application Development Android

Content Provider. Introduction 01/03/2016. Session objectives. Content providers. Android programming course. Introduction. Built-in Content Provider

Mobile Application Development Android

States of Activities. Active Pause Stop Inactive

Introduction to Android

Multiple Activities. Many apps have multiple activities

Android Application Development

CS 528 Mobile and Ubiquitous Computing Lecture 4a: Fragments, Camera Emmanuel Agu

UNDERSTANDING ACTIVITIES

Android Programming Lecture 8: Activities, Odds & Ends, Two New Views 9/28/2011

CMSC436: Fall 2013 Week 3 Lab

Android. Mobile operating system developed by Google A complete stack. Based on the Linux kernel Open source under the Apache 2 license

Programming with Android: Intents. Luca Bedogni. Dipartimento di Scienze dell Informazione Università di Bologna

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

Android Exam AND-401 Android Application Development Version: 7.0 [ Total Questions: 129 ]

Services are software components designed specifically to perform long background operations.

ACTIVITY, FRAGMENT, NAVIGATION. Roberto Beraldi

stolen from Intents and Intent Filters

Android System Architecture. Android Application Fundamentals. Applications in Android. Apps in the Android OS. Program Model 8/31/2015

Mobile User Interfaces

Software Practice 3 Today s lecture Today s Task

Introduction to Android

Android Programming Lecture 7 9/23/2011

Vienos veiklos būsena. Theory

Android for Ubiquitous Computing Researchers. Andrew Rice University of Cambridge 17-Sep-2011

Android Basics. Android UI Architecture. Android UI 1

Android framework. How to use it and extend it

Programming in Android. Nick Bopp

Questions and Answers. Q.1) Which of the following is the most ^aeuroeresource hungry ^aeuroepart of dealing with activities on android?

Lifecycle-Aware Components Live Data ViewModel Room Library

CS 4330/5390: Mobile Application Development Exam 1

MARS AREA SCHOOL DISTRICT Curriculum TECHNOLOGY EDUCATION

Introduction to Android Development

Software Practice 3 Today s lecture Today s Task Porting Android App. in real device

INTRODUCTION TO ANDROID

CMSC436: Fall 2013 Week 4 Lab

ANDROID SERVICES, BROADCAST RECEIVER, APPLICATION RESOURCES AND PROCESS

Mobile Application Development Android

Real-Time Embedded Systems

Android Programming Lecture 2 9/7/2011

Intents. 18 December 2018 Lecture Dec 2018 SE 435: Development in the Android Environment 1

Lecture 6: Android XML, Inversion of Control, Timers (Handlers), Activity

Services. service: A background task used by an app.

Why using intents. Activity. Screen1 Screen 2

EMBEDDED SYSTEMS PROGRAMMING Application Basics

Embedded Systems Programming - PA8001

MOBILE APPLICATION DEVELOPMENT LECTURE 10 SERVICES IMRAN IHSAN ASSISTANT PROFESSOR

Android Programming (5 Days)

Answers to Exercises

REMOTE ACCESS TO ANDROID DEVICES. A Project. Presented to the faculty of the Department of Computer Science. California State University, Sacramento

Introduction to Android development

Agenda. Overview of Xamarin and Xamarin.Android Xamarin.Android fundamentals Creating a detail screen

Produced by. Mobile Application Development. David Drohan Department of Computing & Mathematics Waterford Institute of Technology

App Development for Smart Devices. Lec #7: Windows Azure

Camera and Intent. Elena Fortini

Getting Started. Dr. Miguel A. Labrador Department of Computer Science & Engineering

The Internet. CS 2046 Mobile Application Development Fall Jeff Davidson CS 2046

Mobile Programming Practice Background processing AsynTask Service Broadcast receiver Lab #5

XML Tutorial. NOTE: This course is for basic concepts of XML in line with our existing Android Studio project.

Android development. Outline. Android Studio. Setting up Android Studio. 1. Set up Android Studio. Tiberiu Vilcu. 2.

ANDROID APPS (NOW WITH JELLY BEANS!) Jordan Jozwiak November 11, 2012

ANDROID DEVELOPMENT. Course Details

Contextual Android Education

Minds-on: Android. Session 1

CS378 -Mobile Computing. Audio

EMBEDDED SYSTEMS PROGRAMMING Android Services

Outline. Admin. Example: TipCalc. Android: Event Handler Blocking, Android Inter-Thread, Process Communications. Recap: Android UI App Basic Concepts

MC Android Programming

Lecture 08. Android Permissions Demystified. Adrienne Porter Felt, Erika Chin, Steve Hanna, Dawn Song, David Wagner. Operating Systems Practical

Android Programming - Jelly Bean

Services. Background operating component without a visual interface Running in the background indefinitely

Transcription:

Application Fundamentals CS 2046 Mobile Application Development Fall 2010

Announcements CMS is up If you did not get an email regarding this, see me after class or send me an email. Still working on room for office hours. Lab Session: Monday 10/25, Upson B7 (Regular class time)

Sites of Interest Android Developers Blog: http://android-developers.blogspot.com/?hl=en Android Central: http://www.androidcentral.com/ Both of these are on the Resources page on the course website.

Recap Components: Activity Service ContentProvider BroadcastReceiver Intents: Action, Data = Implicit Action, Data, Component = Explicit

Additional Components of Intents Category: describe the kind of component that should handle the intent. CATEGORY_LAUNCHER: Activity should appear in launcher. CATEGORY_PREFERENCE: Activity defines preferences for an application. Extras: Key-value pairs for additional information. ACTION_HEADSET_PLUG: state for plug or unplug Flags: Mainly, instruct system how to launch Activity FLAG_ACTIVITY_NO_ANIMATION: no animation when launching new activities

Accessing Application Components How do Activities, Services, etc. get launched? In Java: Write a Class to perform some task. This is still the same. Write a main method which calls a constructor of Class and runs any method. This is not the way Android works. Depending on the type of object, Android will call the constructor and manage its lifecycle.

Contexts The Context class provides access to system functions and services. Most functions which involve the Android framework require use of a Context object. Activities and Services extend Context, so they can call methods from the class directly. BroadcastReceivers receive an input Context for their event handling function. ContentProviders call getcontext() to obtain a Context object.

Activities Launch an Activity by calling startactivity(intent) Subactivities: startactivityforresult Takes an Intent as input, as well as an integer code. When subactivity exits, returns a result code. Original activity s onactivityresult method is called. Note this is asynchronous (non-blocking). Activities form a stack New activities appear at the top of the stack (i.e. on screen) Pressing back button goes to previous activity (usually)

Tasks Android groups the activities of one application into a single task = stack of related activities. User presses HOME and launches a new application: Moves current task to background Starts new task, puts default Activity for new application on top of stack. If application is resumed, the old task (with previous stack) is restored.

Activity Lifecycle All startactivity cares about is making sure the Activity is launched. If it s already launched, just brings it to the front. How does an Activity get managed? Event-driven model: Activity has functions to handle each event: oncreate, onresume, onpause, etc. Can take default behavior, or override. All Activities must override oncreate() to do anything. Any overridden method must call through to superclass method.

Activity Lifecycle From http://developer.android.com/reference/android/app/activity.html:

Activity Lifecycle Three states: Active = In the foreground, running. Paused = Still visible, but obscured by another Activity which takes up part of the screen (or is transparent). Same as active, but may be killed if running very low on memory. Stopped = Not visible on the screen.

Activity Lifecycle oncreate() Called when Activity is first created Prepare GUI, other initialization steps. onresume() Called when Activity is now on top of the stack. Update GUI values Note: This is called when Activity is first launched! onpause() Activity is about to disappear. Commit unsaved data, stop any CPU-intensive tasks.

Service Lifecycle Two types: Do some background work on request: Just call startservice() much like an Activity Service has onstartcommand() [or onstart()] to handle this. Service will keep running even after command is executed: best practice to stop with stopself(startid) at end. Ongoing communication Example: Music player Use bindservice() to make a persistent connection. Client gets an object to make calls to service. We ll discuss this more when we talk about background tasks.

Other Lifecycles ContentProviders: ContentResolver cr = Context.getContentResolver(); Access through querying content:// URIs Example: cr.query(content://android.provider.contacts.phones.contact_uri, ) Have query, insert, delete, etc. methods. More on this in the data storage lecture. BroadcastReceivers: Awoken by a system broadcast. Extremely simple just an onreceive handler. Gets Context and Intent describing broadcast.

Application Resources Separate anything that isn t code out of the code Example: Strings, images Make it easy to support different device configurations i.e. different languages, screen sizes Common files in res/ directory: drawable/icon.png: Icon for the program in launcher layout/main.xml: User interface for main Activity values/strings.xml: Any Strings appearing in UI

R.java Eclipse combs through res/ directory, generating Java class to access resources in code. Examples: R.string.<string_name>, R.layout.<layout_name> Accessing resources through the R class lets Android determine the right resource to use.

Configuration Changes Default Android behavior: If configuration changes, restart Activity. Examples: Pull out hardware keyboard, rotate screen Easy way to ensure correct resources are used. Sometimes, this approach takes too long. What if Activity takes a few moments to load data? Can override onconfigurationchanged() to prevent restart and still handle certain common changes.

Android Manifest The last piece of an application. XML file The metadata about the application and its components. Application: Name, icon, version, required Android version What permissions does this application need? What features does this application need or use?

Android Manifest For each component: Specify intent filters so Android knows the Intents that each component can handle. Activity Specify the action android.intent.action.main and the category android.intent.category.launcher for default activity shows up in launcher. Specify other actions that this activity can handle, i.e. the types of files it can view, or URLs it can access. BroadcastReceiver Specify the events that this receiver wants to handle.

Intent Matching What does it mean for an intent filter to match an intent? Action specified in Intent must match one of the Actions listed in the filter. A filter must list at least one action. An intent with no action matches all filters (with >1 action). Every category in the Intent must match a category in the filter. Filter can have extra categories, not Intent. The data (URI + MIME type) in the Intent must match Matching rules are complex see http://developer.android.com/guide/topics/intents/intentsfilters.html

Multiple Intent Filters A component can specify multiple intent filters. If any of them match an Intent during resolution, the component may be started. Up to the component to figure out what action to take. Activity calls getintent() to obtain the Intent with which it was started. What if no filters are specified?

Android Application So what is an Android application? Answer:.apk file Desktop equivalent the.jar file Contains code, resources, anything needed by app.