Asynchronous Task (AsyncTask) in Android

Slides:



Advertisements
Similar presentations
Prepared by: Prepared by: Jameela Rabaya Jameela Rabaya Fatima Darawsha Fatima Darawsha.
Advertisements

USING ANDROID WITH THE INTERNET. Slide 2 Network Prerequisites The following must be included so as to allow the device to connect to the network The.
Intro to Threading CS221 – 4/20/09. What we’ll cover today Finish the DOTS program Introduction to threads and multi-threading.
Task Scheduling and Distribution System Saeed Mahameed, Hani Ayoub Electrical Engineering Department, Technion – Israel Institute of Technology
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 16 Applets.
Intro to Computers Test 1 – Chapters 1 & 2 and Windows Fall 2005.
Cosc 4730 Brief return Sockets And HttpClient And AsyncTask.
Installing software on personal computer
Networking Nasrullah. Input stream Most clients will use input streams that read data from the file system (FileInputStream), the network (getInputStream()/getInputStream()),
Applets  The Applet Class  The HTML Tag F Passing Parameters to Applets.
CS378 - Mobile Computing Web - WebView and Web Services.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Concurrency in Android with.
Software Architecture of Android Yaodong Bi, Ph.D. Department of Computing Sciences University of Scranton.
Networking: Part 2 (Accessing the Internet). The UI Thread When an application is launched, the system creates a “main” UI thread responsible for handling.
CS378 - Mobile Computing Web - WebView and Web Services.
Chapter 34 Java Technology for Active Web Documents methods used to provide continuous Web updates to browser – Server push – Active documents.
Asynchronous Tasks with Android Anthony Dahanne, Ing Jr identi.ca/twitter blog : Android Montreal, le 01/09/2010.
CSC 205 – Java Programming II Applet. Types of Java Programs Applets Applications Console applications Graphics applications Applications are stand-alone.
Working in the Background Radan Ganchev Astea Solutions.
Introduction to Socket Programming in Android Jules White Bradley Dept. of Electrical and Computer Engineering Virginia Tech
MAKANI ANDROID APPLICATION Prepared by: Asma’ Hamayel Alaa Shaheen.
CS378 - Mobile Computing Responsiveness. An App Idea From Nifty Assignments Draw a picture use randomness Pick an equation at random Operators in the.
Android networking 1. Network programming with Android If your Android is connected to a WIFI, you can connect to servers using the usual Java API, like.
ALAA M. ALSALEHI SOFTWARE ENGINEER AT IUG Multithreading in Android.
Chapter 14 Applets and Advanced GUI  The Applet Class  The HTML Tag F Passing Parameters to Applets F Conversions Between Applications and Applets F.
USER DOCUMENTATION Zaheer Shaikh Noshaba Bakht Eric Tse Mayyapan Ramaswamy.
Developing Applications with the CSI Framework A General Guide.
Android Threads. Threads Android will show an “ANR” error if a View does not return from handling an event within 5 seconds Or, if some code running in.
HW#9 Clues CSCI 571 Fall, HW#9 Prototype
Recap of Part 1 Terminology Windows FormsAndroidMVP FormActivityView? ControlViewView? ?ServiceModel? Activities Views / ViewGroups Intents Services.
Conway’s Game Of Live 1 Fall 2014 CS7020: Game Design and Development.
CHAPTER 6 Threads, Handlers, and Programmatic Movement.
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.
Programming with Java. Chapter 1 Focuses on: –components of a computer –how those components interact –how computers store and manipulate information.
USING ANDROID WITH THE INTERNET. Slide 2 Lecture Summary Getting network permissions Working with the HTTP protocol Sending HTTP requests Getting results.
CHAPTER 7 Operating System Copyright © Cengage Learning. All rights reserved.
INTRODUCTION TO COMPUTERS. A computer system is an electronic device used to input data, process data, store data for later use and produce output in.
Threads and Swing Multithreading. Contents I. Simulation on Inserting and Removing Items in a Combo Box II. Event Dispatch Thread III. Rules for Running.
Multithreading Chapter 6. Objectives Understand the benefits of multithreading on Android Understand multi-threading fundamentals Know the Thread class.
DISCOVERING COMPUTERS 2018 Digital Technology, Data, and Devices
Plan for today Open-Closed and Quizmaster
Small talk with the UI thread
Lecture 1-Part 2: Operating-System Structures
2. OPERATING SYSTEM 2.1 Operating System Function
Design Components are Code Components
Reactive Android Development
Instructor: Mazhar Hussain
Hands-On Microsoft Windows Server 2008
CS240: Advanced Programming Concepts
Android Mobile Application Development
MVC and other n-tier Architectures
Introduction to Operating System (OS)
Lecture 28 Concurrent, Responsive GUIs
Android Programming Lecture 8
Application Development A Tutorial Driven Course
CS371m - Mobile Computing Responsiveness.
Multithreaded Programming
Android Topics UI Thread and Limited processing resources
Mobile Computing With Android ACST 4550 Android Database Storage
Android Topics Asynchronous Callsbacks
Graphical User Interfaces in Java Event-driven programming
Design Components are Code Components
Android Topics Threads and the MessageQueue
Android Developer Fundamentals V2
Java Programming COMP-417 Applet
Threads, Handlers, and AsyncTasks
Mobile Programming Dr. Mohsin Ali Memon.
Mobile Computing Dr. Mohsin Ali Memon.
Geographical information system: Definition and components
Android Threads Dimitar Ivanov Mobile Applications with Android
Presentation transcript:

Asynchronous Task (AsyncTask) in Android

AsyncTask One of the most important problems in Android development is the User Interface (UI) responsiveness. Part of this is the fault of Android implementation, but much faults lies on the developer. A key to a good GUI performance in Android development is to move as much work as possible off from the UI thread into the background. Using AsyncTasks is one of the easiest way to do this. When to use AsyncTask? An AsyncTask is designed to be a helper class around threads and handlers. As described in the Android documentation: “AsyncTask enables proper and easy use of the UI thread. This class allows to perform background operations and publish results on the UI thread without having to manipulate threads and/or handlers.” Simply said: An AsyncTask is used to do some computation in background and publish the result on the UI thread.

AsyncTask – Cont’d AsyncTasks ideally are designed to perform operations in background which take at most a few seconds. It is not recommended to use them for downloading megabytes of data from servers or doing CPU intensive tasks, such as image processing. If you want to keep threads running for a long period of time, it is strongly recommended to use Java threads or classes such as java.util.concurrent.Executor or java.util.concurrent.ThreadPoolExecutor in combination with android.os.Handler to publish the results on the UI thread. Note : If you need to do network operations using either Java threads or AsyncTask. In Android 4 and above attempting to access the network from the UI thread will throw an exception.

AsyncTask – Life Cycle

AsyncTask – Life Cycle - Cont’d

AsyncTask – Usage To use AsyncTask you must subclass it. An AsyncTask is started via the execute() method. The execute() method calls the doInBackground() method. AsyncTask is an intelligent thread that is recommended to be used. It is intelligent as it can help with it’s methods, and there are two methods that run on the UI thread, which is good to update UI components. Use AsyncTask for: Simple network operations which do not require downloading a lot of data Disk-bound tasks that might take less than a few milliseconds