Lec 06 AsyncTask Local Services IntentService Broadcast Receivers.

Slides:



Advertisements
Similar presentations
Services. Application component No user interface Two main uses Performing background processing Supporting remote method execution.
Advertisements

Cosc 5/4730 Android Services. What is a service? From android developer web pages: Most confusion about the Service class actually revolves around what.
1 Frameworks. 2 Framework Set of cooperating classes/interfaces –Structure essential mechanisms of a problem domain –Programmer can extend framework classes,
1 Working with the Android Services Nilanjan Banerjee Mobile Systems Programming University of Arkansas Fayetteville, AR
Android Security Enforcement and Refinement. Android Applications --- Example Example of location-sensitive social networking application for mobile phones.
Emerging Platform#4: Android Bina Ramamurthy.  Android is an Operating system.  Android is an emerging platform for mobile devices.  Initially developed.
Chien-Chung Shen Manifest and Activity Chien-Chung Shen
Intro to Android Programming George Nychis Srinivasan Seshan.
Networking Nasrullah. Input stream Most clients will use input streams that read data from the file system (FileInputStream), the network (getInputStream()/getInputStream()),
UI Design Patterns & Best Practices Mike Wolfson July 22, 2010.
© Keren Kalif Intro to Android Development Written by Keren Kalif, Edited by Liron Blecher Contains slides from Google I/O presentation.
Software Architecture of Android Yaodong Bi, Ph.D. Department of Computing Sciences University of Scranton.
@2011 Mihail L. Sichitiu1 Android Introduction Platform Overview.
Cosc 5/4730 Introduction: Threads, Android Activities, and MVC.
Networking: Part 2 (Accessing the Internet). The UI Thread When an application is launched, the system creates a “main” UI thread responsible for handling.
Lec 04 Content Providers Adapters CursorLoaders Advanced Debugging.
Rajab Davudov. Agenda Eclipse, ADT and Android SDK APK file Fundamentals – Activity – Service – Content Provider – Broadcast Receiver – Intent Hello World.
Using Intents to Broadcast Events Intents Can be used to broadcast messages anonymously Between components via the sendBroadcast method As a result Broadcast.
Android ICC Part II Inter-component communication.
COMP 365 Android Development.  Perform operations in the background  Services do not have a user interface (UI)  Can run without appearing on screen.
This work is licensed under the Creative Commons Attribution 4.0 International License. To view a copy of this license, visit
Mobile Application Development using Android Lecture 2.
DUE Hello World on the Android Platform.
CS378 - Mobile Computing Intents.
16 Services and Broadcast Receivers CSNB544 Mobile Application Development Thanks to Utexas Austin.
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.
Working in the Background Radan Ganchev Astea Solutions.
Android 13: Services and Content Providers Kirk Scott 1.
Services A Service is an application component that can perform long-running operations in the background and does not provide a user interface. An application.
Services 1 CS440. What is a Service?  Component that runs on background  Context.startService(), asks the system to schedule work for the service, to.
NOAA Weather Patrick Wolfram. What it does Allows user to specify a zip code Performs HTTP GET requests on noaa.gov for the specified zip code Displays.
DKU-MUST Mobile ICT Education Center 10. Activity and Intent.
HW#9 Clues CSCI 571 Fall, HW#9 Prototype
Recap of Part 1 Terminology Windows FormsAndroidMVP FormActivityView? ControlViewView? ?ServiceModel? Activities Views / ViewGroups Intents Services.
Services Background operating component without a visual interface Running in the background indefinitely Differently from Activity, Service in Android.
CSE 486/586, Spring 2014 CSE 486/586 Distributed Systems Android Programming Steve Ko Computer Sciences and Engineering University at Buffalo.
Lecture 2: Android Concepts
Technische Universität München Services, IPC and RPC Gökhan Yilmaz, Benedikt Brück.
Lecture 6: Process and Threads Topics: Process, Threads, Worker Thread, Async Task Date: Mar 1, 2016.
Android App Development. Android Architecture Linux kernel Libraries Android Runtime Application Framework Applications Application Components Activities.
Intents and Broadcast Receivers Dr. David Janzen Except as otherwise noted, the content of this presentation is licensed under the Creative Commons Attribution.
Android intro Building UI #1: interactions. AndroidManifest.xml permissions 2.
Services. What is a Service? A Service is not a separate process. A Service is not a thread. A Service itself is actually very simple, providing two main.
USING ANDROID WITH THE INTERNET. Slide 2 Lecture Summary Getting network permissions Working with the HTTP protocol Sending HTTP requests Getting results.
Developing Android Services. Objectives Creating a service that runs in background Performing long-running tasks in a separate thread Performing repeated.
CS371m - Mobile Computing Intents 1. Allow us to use applications and components that are already part of Android System – start activities – start services.
Lecture 2: Android Concepts
Broadcast receivers.
CS371m - Mobile Computing Services and Broadcast Receivers
Lecture 7: Service Topics: Services, Playing Media.
Instructor: Mazhar Hussain
Lecture 7: Android Services
Activities and Intents
Android Mobile Application Development
Lecture 6: Process, Thread, Task
Reactive Android Development
Android Application Development android.cs.uchicago.edu
Android Programming Lecture 9
Developing Android Services
Android Programming Lecture 8
Android Topics Asynchronous Callsbacks
lec 05 Admin stuff; schedule IOS versus Android Preferences
Android Developer Fundamentals V2
Service Services.
Lecture 7: Service Topics: Services, Broadcast Receiver, Playing Media.
Lecture 6: Process, Thread, Task
Lecture 2: Android Concepts
Mobile Programming Dr. Mohsin Ali Memon.
CIS 470 Mobile App Development
Presentation transcript:

lec 06 AsyncTask Local Services IntentService Broadcast Receivers

In this example, MyTask extends AsyncTask Params: 1/ (String) passed into doInBackground(String... strUrls) 2/ (Integer) The value passed into onProgressUpdate(Integer... intUpdates) 3/ (Bitmap) returned from doInBackground() and used as input to onPostExecute(Bitmap bmp) AsyncTask

An Activity can start a Service via either the startService() method or stop the service via the stopService() method. A Service will not automatically run in its own thread, though it can. You can specify that your Service runs in a separate process via the android:process=":process_description" attribute. The colon means it's private to the app, if the colon is missing then it's global to everything. <service android:name=".WordService" android:process=":my_process" > Without the process attribute, the service runs in the main thread of the hosting process. Therefore you should run performance intensive tasks in the background. You can use IntentService for this. Service

Services >A first-class component in Android that must be declared in the the manifest >Has no graphical user-interface >Used for long-running background tasks; typically networking, I/O, interaction with content providers, multimedia >There are two classes of Services; Service Started (local) Bound (remote) Used within the same app Across apps

onStartCommand() returns a flag which tells the OS that the service is either sticky or not_sticky. Both codes are only relevant when the phone runs out of memory and kills the service before it finishes executing. START_STICKY tells the OS to recreate the service after it has enough memory and call onStartCommand() again with a null intent. START_NOT_STICKY tells the OS to not bother recreating the service again. There is also a third code START_REDELIVER_INTENT that tells the OS to recreate the service AND redeliver the same intent to onStartCommand(). Service

An IntentService: 1/ running in a separate background thread 2/ once done, it terminates itself. The IntentService class offers the onHandleIntent() method which will be asynchronously called by the Android system. This is similar to doInBackground() for AsyncTask. IntentService

If the Activity want to interact with the Activity it can use the bindService() method of the service. This requires an ServiceConnection object which allows to connect to the Service and which return a IBinder object. This IBinder object can be used by the activity to communicate with the Service. Android Interface Definition Language (AIDL) for remote services Will cover in more detail in a future lecture. Bound and Advanced Services

Broadcast Reievers >You can't trigger the system Broadcasts >You can define intent filters and also your own broadcast types Broadcast Receivers

Broadcast Receivers (aka Receivers) >You must specify the intent filter in the Android Manifest file (or programmatically). The first is the constant defined as a String, the second is the value. Examples: ACTION_AIRPLANE_MODE_CHANGED android.intent.action.AIRPLANE_MODE ACTION_BATTERY_LOW android.intent.action.BATTERY_LOW ACTION_BOOT_COMPLETED android.intent.action.BOOT_COMPLETED ACTION_TIMEZONE_CHANGED android.intent.action.TIMEZONE_CHANGED

Broadcast Receivers 1/ extend BroadcastReceiver 2/ override onRecieve()

Broadcast Receivers 1/ extend BroadcastReceiver 2/ override onRecieve()

A: AsyncTask: How to get/parse JSON data (weather data) from RESTful web service (with recipe) B: MediaStore: Taking pictures and videos and storing them for use in an app (not the standard gallery) (with recipe) C: Voice Recognition: How to use voice recognition inside an app (with recipe) D: Tracking locations (using GPS) for a jog or a race. Data capture so that I can map where I went and how far I traveled, avg speed (with recipe) Student presentations :