SlideShare a Scribd company logo
Working in the Background




Vladimir Kotov     Working in the Background   1
Android Runtime




Vladimir Kotov       Working in the Background   2
Android Runtime
     Zygote spawns VM processes
      ●   Already has core libraries loaded
      ●   When an app is launched, zygote is forked
      ●   Fork core libraries are shared with zygote




Vladimir Kotov                Working in the Background   3
Android Runtime
     By default
      ●   system assigns each application a unique Linux user ID
      ●   every application runs in its own Linux process
      ●   each process has its own virtual machine




Vladimir Kotov                Working in the Background            4
Process v. Thread
   Process
    ●   typically independent
    ●   has considerably more state
        information than thread
    ●   separate address spaces
    ●   interact only through system IPC


   Thread
    ●   subsets of a process
    ●   multiple threads within a process
        share process state, memory, etc
    ●   threads share their address space



Vladimir Kotov                     Working in the Background   5
“Killer” Application




Vladimir Kotov         Working in the Background   6
Android Process and Thread
 ●   Android starts a new Linux            ●   System creates a thread of
     process for the application               execution for the application
     with a single thread of                   (“main” / “UI” thread) when
     execution                                 application is launched
 ●   Android can shut down a               ●   System does not create a
     process when memory is low,               separate thread for each
     application components                    instance of a component
     running in the process are                 ●   components are
     destroyed
                                                    instantiated in the UI
                                                    thread
                                                ●   system calls (callbacks) to
                                                    components are
                                                    dispatched from UI thread
Vladimir Kotov              Working in the Background                          7
Android Single Threading Model
Looper - runs a message loop for a
  thread

Message - defines a message
  containing a description and
  arbitrary data object that can be
  sent to a Handler

Handler - allows to send and process
  Message and Runnable objects
  associated with a thread's
  MessageQueue. Each Handler
  instance is associated with a single
  thread and that thread's message
  queue.
Vladimir Kotov               Working in the Background   8
“Killer” application. Postmortem

1) User clicks a button on screen
2) UI thread dispatches the click
event to the widget
3) OnClick handler sets its text
and posts an invalidate request
to the event queue
4) UI thread dequeues the
request and notifies the widget
that it should redraw itself



Vladimir Kotov             Working in the Background   9
Rules of Thumb
 ●   Do not block the UI thread
      ●   Potentially long running operations (ie. network or
          database operations, expensive calculations, etc.)
          should be done in a child thread


 ●   Do not access the Android UI toolkit from
     outside the UI thread
      ●   Android UI toolkit is not thread-safe and must always
          be manipulated on the UI thread


 ●   Keep your app Responsive

Vladimir Kotov                   Working in the Background        10
Worker Threads
 ●   If you have operations to perform that are not
     instantaneous, you should make sure to do them in
     separate threads ("background" or "worker" threads)




Vladimir Kotov           Working in the Background         11
Worker Threads
 ●   If you have operations to perform that are not
     instantaneous, you should make sure to do them in
     separate threads ("background" or "worker" threads)




Vladimir Kotov           Working in the Background         12
Worker Threads
 ●   Activity.runOnUiThread(Runnable)
 ●   View.post(Runnable)
 ●   View.postDelayed(Runnable, long)




Vladimir Kotov             Working in the Background   13
AsyncTask
 ●   Best practice pattern for moving your time-consuming
     operations onto a background Thread
 ●   Allows to perform asynchronous work on user interface
      ●   performs blocking operations in a worker thread
                 doInBackground()

      ●   publishes the results on the UI thread
                 onPostExecute()

      ●   does not require handling threads and handlers yourself
Vladimir Kotov                Working in the Background        14
AsyncTask in Action




Vladimir Kotov         Working in the Background   15
What's Next ...




Vladimir Kotov      Working in the Background   16
Vladimir Kotov   Working in the Background   17
AsyncTask Problem
    Activity.onRetainNonConfigurationInstance()
      ●   Called by the system, as part of destroying an activity due to
          a configuration change, when it is known that a new instance
          will immediately be created for the new configuration


    Activity.getLastNonConfigurationInstance()
      ●   Retrieve the non-configuration instance data that was
          previously returned by onRetainNonConfigurationInstance().
          This will be available from the initial onCreate and onStart
          calls to the new instance, allowing you to extract any useful
          dynamic state from the previous instance


Vladimir Kotov                 Working in the Background                   18
AsyncTask Problem




Vladimir Kotov        Working in the Background   19
Services
                                Broadcast
                                Receivers

                 Intents                                   Activities




        Services                                         Views


                  Content
                 Providers
Vladimir Kotov               Working in the Background              20
Services
     When a Service Used
 ●   Application need to run
     processes for a long time without
     any intervention from the user, or
     very rare interventions
 ●   These background processes
     need to keep running even when
     the phone is being used for other
     activities / tasks
 ●   Network transactions, play
     music, perform file I/O, etc

Vladimir Kotov             Working in the Background   21
Services and Notifications
 ●   Service does not implement any
     user interface
 ●   Service “notifies” the user through
     the notification (such as status bar
     notification)
 ●   Service can give a user interface for
     binding to the service or viewing the
     status of the service or any other
     similar interaction




Vladimir Kotov             Working in the Background   22
NB!

 ●   Service does not run in a separate process
 ●   Service does not create its own thread
 ●   Service runs in the main thread




Vladimir Kotov        Working in the Background   23
Service Lifecycle




Vladimir Kotov       Working in the Background   24
Starting a Service
 ●   Context.startService()
      ●   Retrieve the service (creating it and calling its onCreate()
          method if needed)
      ●   Call onStartCommand(Intent, int, int) method of the service
          with the arguments supplied

 ●   The service will continue running until
     Context.stopService() or stopSelf() is called


 ●   <service android:name="com.example.service.MyService"/>

Vladimir Kotov                Working in the Background                  25
IntentService
 Uses a worker thread to handle            ●
                                               Creates a default worker
   all start requests, one at a                thread that executes all
   time. The best option if you                intents delivered to
   don't require that your                     onStartCommand()
   service handle multiple
   requests simultaneously.
                                           ●
                                               Creates a work queue that
                                               passes one intent at a time
 “Set it and forget it” – places
                                               to your onHandleIntent()
   request on Service Queue,               ●
                                               Stops the service after all
   which handles action (and                   start requests have been
   “may take as long as                        handled
   necessary”)

Vladimir Kotov              Working in the Background                        26
IntentService




Vladimir Kotov     Working in the Background   27
Android Web Service




Vladimir Kotov         Working in the Background   28
Android and HTTP
 ●   Connecting to an Internet Resource
          <uses-permission
          android:name=”android.permission.INTERNET”/>
 ●   Android includes two HTTP clients:
      ●   HttpURLConnection
      ●   Apache HTTP Client
 ●   Support HTTPS, streaming uploads and downloads,
     configurable timeouts, IPv6 and connection pooling



Vladimir Kotov            Working in the Background       29
HttpURLConnection
 ●   HttpURLConnection is a general-purpose, lightweight
     HTTP client suitable for most applications




Vladimir Kotov           Working in the Background         30
Apache HttpClient
 ●   Extensible HTTP clients suitable for web browsers. Have
     large and flexible APIs.




Vladimir Kotov           Working in the Background             31
JSON Parsing with JSONObject
 ●   JSON (JavaScript Object Notation), is a text-based open standard
     designed for human-readable data interchange. It is derived from the
     JavaScript scripting language for representing simple data structures
     and associative arrays, called objects.


 ●   Built-in JSONTokener / JSONObject                            {

     JSONTokener jsonTokener = new JSONTokener(response);         "My Purchase List":[

     JSONObject object = (JSONObject) jsonTokener.nextValue();    {"name":"Bread","quantity":"11"}],
     object = object.getJSONObject("patient");                    "Mom Purchase List":[
     patientName = object.getString("name");                      {"name":"Tomato","quantity":"2"}]
     patientSurname = object.getString("surname");                }




Vladimir Kotov                        Working in the Background                               32
JSON Parsing with GSON
 ●   Gson is a Java library that can be used to convert Java
     Objects into their JSON representation. It can also be used
     to convert a JSON string to an equivalent Java object
      ●   Simple toJson() and fromJson() methods to convert
          Java objects to JSON and vice-versa
      ●   Extensive support of Java Generics
      ●   Allow custom representations for objects
      ●   Support arbitrarily complex objects (with deep
          inheritance hierarchies and extensive use of generic
          types)


Vladimir Kotov              Working in the Background            33
JSON Parsing with GSON




Vladimir Kotov      Working in the Background   34
Workshop
 ●   Purchase list synchronization                     Example
                                                       http://kotov.lv/JavaguryServices/purchases/
      ●   Web-service (REST)                           vladkoto
            –    https://github.com/rk13/java
                 guru-services
                                                       {
            –    http://kotov.lv/JavaguryServ
                                                        "My Purchase List":[
                 ices/purchases/
                                                       {"name":"Bread","quantity":"11"},
                                                       {"name":"Jameson Wiskey","quantity":"1"}],
      ●   API
                                                        "Mom Purchase List":[
            –    http://kotov.lv/JavaguryServ
                 ices/purchases/{TOKEN}                {"name":"Cranberry","quantity":"1kg"},

            –    GET / POST                            {"name":"Tomato","quantity":"2"}]
                                                       }



Vladimir Kotov                       Working in the Background                                  35
Sync Purchase Lists
 ●   Task1: Import purchase lists
      ●   Use AsyncTask
      ●   Load json from service
      ●   Convert and display
      ●   HttpTask.java for starting point

 ●   Task2: Export purchase lists
      ●   Use IntentService
      ●   Convert and push json to server
      ●   ExportService.java for starting point
Vladimir Kotov                Working in the Background   36
Sync Purchase Lists
 ●   Task3: Sync service configuration via preferences


 ●   Task4: Export/Import adoption in Purchase list app




Vladimir Kotov             Working in the Background      37

More Related Content

PDF
Asynchronous Programming in Android
PDF
Internals of AsyncTask
PPTX
Efficient Android Threading
PDF
Android concurrency
PDF
Android development training programme , Day 3
PDF
Android Threading
PPTX
Multithreading and concurrency in android
PPT
Android - Thread, Handler and AsyncTask
Asynchronous Programming in Android
Internals of AsyncTask
Efficient Android Threading
Android concurrency
Android development training programme , Day 3
Android Threading
Multithreading and concurrency in android
Android - Thread, Handler and AsyncTask

What's hot (20)

ODP
Android App Development - 07 Threading
PPS
09 gui 13
PDF
10 ways to improve your Android app performance
PDF
Multithreading in Android
PPTX
Javascript internals
PPTX
Kalp Corporate Node JS Perfect Guide
PDF
(COSCUP 2015) A Beginner's Journey to Mozilla SpiderMonkey JS Engine
PPTX
Cut your Dependencies with Dependency Injection - .NET User Group Osnabrueck
PDF
Toward dynamic analysis of obfuscated android malware
PDF
Recon2016 shooting the_osx_el_capitan_kernel_like_a_sniper_chen_he
PDF
Deploying JHipster Microservices
ODP
Jenkins 101: Continuos Integration with Jenkins
PPT
Singleton Object Management
PDF
Android Loaders : Reloaded
PDF
Concurrency Utilities in Java 8
PPTX
Qt test framework
 
PPT
Inside the Android application framework - Google I/O 2009
PPTX
OpenDaylight Developer Experience 2.0
ODP
Unit Test Android Without Going Bald
PPTX
Introduction to NodeJS
Android App Development - 07 Threading
09 gui 13
10 ways to improve your Android app performance
Multithreading in Android
Javascript internals
Kalp Corporate Node JS Perfect Guide
(COSCUP 2015) A Beginner's Journey to Mozilla SpiderMonkey JS Engine
Cut your Dependencies with Dependency Injection - .NET User Group Osnabrueck
Toward dynamic analysis of obfuscated android malware
Recon2016 shooting the_osx_el_capitan_kernel_like_a_sniper_chen_he
Deploying JHipster Microservices
Jenkins 101: Continuos Integration with Jenkins
Singleton Object Management
Android Loaders : Reloaded
Concurrency Utilities in Java 8
Qt test framework
 
Inside the Android application framework - Google I/O 2009
OpenDaylight Developer Experience 2.0
Unit Test Android Without Going Bald
Introduction to NodeJS
Ad

Similar to Android Working in the Background (20)

PDF
Inside the android_application_framework
PDF
Android101
PPT
Android overview
PPTX
Threads handlers and async task, widgets - day8
PDF
Explore Android Internals
PPTX
Threads in Mobile Application Development.pptx
PDF
Android life cycle
PPTX
Process Management in Android
PPTX
Tk2323 lecture 11 process and thread
PDF
Android Jumpstart Jfokus
PDF
INTRODUCTION TO FORMS OF SERVICES AND ITS LIFE CYCLE
PPTX
Android Application Development
PDF
Marakana android-java developers
PPTX
Andriod Lecture 8 A.pptx
PDF
Android Internals at Linaro Connect Asia 2013
PPTX
mobile development with androiddfdgdfhdgfdhf.pptx
PPT
"Android" mobilių programėlių kūrimo įvadas #2
PPT
PPTX
Data Transfer between Activities & Databases
PDF
Mobile Application Development -Lecture 09 & 10.pdf
Inside the android_application_framework
Android101
Android overview
Threads handlers and async task, widgets - day8
Explore Android Internals
Threads in Mobile Application Development.pptx
Android life cycle
Process Management in Android
Tk2323 lecture 11 process and thread
Android Jumpstart Jfokus
INTRODUCTION TO FORMS OF SERVICES AND ITS LIFE CYCLE
Android Application Development
Marakana android-java developers
Andriod Lecture 8 A.pptx
Android Internals at Linaro Connect Asia 2013
mobile development with androiddfdgdfhdgfdhf.pptx
"Android" mobilių programėlių kūrimo įvadas #2
Data Transfer between Activities & Databases
Mobile Application Development -Lecture 09 & 10.pdf
Ad

More from Vladimir Kotov (8)

PDF
e-Business - Mobile development trends
PDF
e-Business - SE trends
PDF
LDP lecture 2
PDF
LDP lecture 1
PDF
Android Internals and Toolchain
PDF
LDP lecture 5
PDF
LDP lecture 4
PDF
LDP lecture 3
e-Business - Mobile development trends
e-Business - SE trends
LDP lecture 2
LDP lecture 1
Android Internals and Toolchain
LDP lecture 5
LDP lecture 4
LDP lecture 3

Recently uploaded (20)

PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Accuracy of neural networks in brain wave diagnosis of schizophrenia
PDF
Machine learning based COVID-19 study performance prediction
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
Empathic Computing: Creating Shared Understanding
PPTX
A Presentation on Artificial Intelligence
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
Spectroscopy.pptx food analysis technology
PPTX
MYSQL Presentation for SQL database connectivity
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PDF
Approach and Philosophy of On baking technology
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
Network Security Unit 5.pdf for BCA BBA.
NewMind AI Weekly Chronicles - August'25-Week II
“AI and Expert System Decision Support & Business Intelligence Systems”
Unlocking AI with Model Context Protocol (MCP)
Mobile App Security Testing_ A Comprehensive Guide.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Accuracy of neural networks in brain wave diagnosis of schizophrenia
Machine learning based COVID-19 study performance prediction
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Empathic Computing: Creating Shared Understanding
A Presentation on Artificial Intelligence
Dropbox Q2 2025 Financial Results & Investor Presentation
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Spectroscopy.pptx food analysis technology
MYSQL Presentation for SQL database connectivity
The Rise and Fall of 3GPP – Time for a Sabbatical?
Group 1 Presentation -Planning and Decision Making .pptx
Approach and Philosophy of On baking technology
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
20250228 LYD VKU AI Blended-Learning.pptx

Android Working in the Background

  • 1. Working in the Background Vladimir Kotov Working in the Background 1
  • 2. Android Runtime Vladimir Kotov Working in the Background 2
  • 3. Android Runtime Zygote spawns VM processes ● Already has core libraries loaded ● When an app is launched, zygote is forked ● Fork core libraries are shared with zygote Vladimir Kotov Working in the Background 3
  • 4. Android Runtime By default ● system assigns each application a unique Linux user ID ● every application runs in its own Linux process ● each process has its own virtual machine Vladimir Kotov Working in the Background 4
  • 5. Process v. Thread Process ● typically independent ● has considerably more state information than thread ● separate address spaces ● interact only through system IPC Thread ● subsets of a process ● multiple threads within a process share process state, memory, etc ● threads share their address space Vladimir Kotov Working in the Background 5
  • 6. “Killer” Application Vladimir Kotov Working in the Background 6
  • 7. Android Process and Thread ● Android starts a new Linux ● System creates a thread of process for the application execution for the application with a single thread of (“main” / “UI” thread) when execution application is launched ● Android can shut down a ● System does not create a process when memory is low, separate thread for each application components instance of a component running in the process are ● components are destroyed instantiated in the UI thread ● system calls (callbacks) to components are dispatched from UI thread Vladimir Kotov Working in the Background 7
  • 8. Android Single Threading Model Looper - runs a message loop for a thread Message - defines a message containing a description and arbitrary data object that can be sent to a Handler Handler - allows to send and process Message and Runnable objects associated with a thread's MessageQueue. Each Handler instance is associated with a single thread and that thread's message queue. Vladimir Kotov Working in the Background 8
  • 9. “Killer” application. Postmortem 1) User clicks a button on screen 2) UI thread dispatches the click event to the widget 3) OnClick handler sets its text and posts an invalidate request to the event queue 4) UI thread dequeues the request and notifies the widget that it should redraw itself Vladimir Kotov Working in the Background 9
  • 10. Rules of Thumb ● Do not block the UI thread ● Potentially long running operations (ie. network or database operations, expensive calculations, etc.) should be done in a child thread ● Do not access the Android UI toolkit from outside the UI thread ● Android UI toolkit is not thread-safe and must always be manipulated on the UI thread ● Keep your app Responsive Vladimir Kotov Working in the Background 10
  • 11. Worker Threads ● If you have operations to perform that are not instantaneous, you should make sure to do them in separate threads ("background" or "worker" threads) Vladimir Kotov Working in the Background 11
  • 12. Worker Threads ● If you have operations to perform that are not instantaneous, you should make sure to do them in separate threads ("background" or "worker" threads) Vladimir Kotov Working in the Background 12
  • 13. Worker Threads ● Activity.runOnUiThread(Runnable) ● View.post(Runnable) ● View.postDelayed(Runnable, long) Vladimir Kotov Working in the Background 13
  • 14. AsyncTask ● Best practice pattern for moving your time-consuming operations onto a background Thread ● Allows to perform asynchronous work on user interface ● performs blocking operations in a worker thread doInBackground() ● publishes the results on the UI thread onPostExecute() ● does not require handling threads and handlers yourself Vladimir Kotov Working in the Background 14
  • 15. AsyncTask in Action Vladimir Kotov Working in the Background 15
  • 16. What's Next ... Vladimir Kotov Working in the Background 16
  • 17. Vladimir Kotov Working in the Background 17
  • 18. AsyncTask Problem Activity.onRetainNonConfigurationInstance() ● Called by the system, as part of destroying an activity due to a configuration change, when it is known that a new instance will immediately be created for the new configuration Activity.getLastNonConfigurationInstance() ● Retrieve the non-configuration instance data that was previously returned by onRetainNonConfigurationInstance(). This will be available from the initial onCreate and onStart calls to the new instance, allowing you to extract any useful dynamic state from the previous instance Vladimir Kotov Working in the Background 18
  • 19. AsyncTask Problem Vladimir Kotov Working in the Background 19
  • 20. Services Broadcast Receivers Intents Activities Services Views Content Providers Vladimir Kotov Working in the Background 20
  • 21. Services When a Service Used ● Application need to run processes for a long time without any intervention from the user, or very rare interventions ● These background processes need to keep running even when the phone is being used for other activities / tasks ● Network transactions, play music, perform file I/O, etc Vladimir Kotov Working in the Background 21
  • 22. Services and Notifications ● Service does not implement any user interface ● Service “notifies” the user through the notification (such as status bar notification) ● Service can give a user interface for binding to the service or viewing the status of the service or any other similar interaction Vladimir Kotov Working in the Background 22
  • 23. NB! ● Service does not run in a separate process ● Service does not create its own thread ● Service runs in the main thread Vladimir Kotov Working in the Background 23
  • 24. Service Lifecycle Vladimir Kotov Working in the Background 24
  • 25. Starting a Service ● Context.startService() ● Retrieve the service (creating it and calling its onCreate() method if needed) ● Call onStartCommand(Intent, int, int) method of the service with the arguments supplied ● The service will continue running until Context.stopService() or stopSelf() is called ● <service android:name="com.example.service.MyService"/> Vladimir Kotov Working in the Background 25
  • 26. IntentService Uses a worker thread to handle ● Creates a default worker all start requests, one at a thread that executes all time. The best option if you intents delivered to don't require that your onStartCommand() service handle multiple requests simultaneously. ● Creates a work queue that passes one intent at a time “Set it and forget it” – places to your onHandleIntent() request on Service Queue, ● Stops the service after all which handles action (and start requests have been “may take as long as handled necessary”) Vladimir Kotov Working in the Background 26
  • 27. IntentService Vladimir Kotov Working in the Background 27
  • 28. Android Web Service Vladimir Kotov Working in the Background 28
  • 29. Android and HTTP ● Connecting to an Internet Resource <uses-permission android:name=”android.permission.INTERNET”/> ● Android includes two HTTP clients: ● HttpURLConnection ● Apache HTTP Client ● Support HTTPS, streaming uploads and downloads, configurable timeouts, IPv6 and connection pooling Vladimir Kotov Working in the Background 29
  • 30. HttpURLConnection ● HttpURLConnection is a general-purpose, lightweight HTTP client suitable for most applications Vladimir Kotov Working in the Background 30
  • 31. Apache HttpClient ● Extensible HTTP clients suitable for web browsers. Have large and flexible APIs. Vladimir Kotov Working in the Background 31
  • 32. JSON Parsing with JSONObject ● JSON (JavaScript Object Notation), is a text-based open standard designed for human-readable data interchange. It is derived from the JavaScript scripting language for representing simple data structures and associative arrays, called objects. ● Built-in JSONTokener / JSONObject { JSONTokener jsonTokener = new JSONTokener(response); "My Purchase List":[ JSONObject object = (JSONObject) jsonTokener.nextValue(); {"name":"Bread","quantity":"11"}], object = object.getJSONObject("patient"); "Mom Purchase List":[ patientName = object.getString("name"); {"name":"Tomato","quantity":"2"}] patientSurname = object.getString("surname"); } Vladimir Kotov Working in the Background 32
  • 33. JSON Parsing with GSON ● Gson is a Java library that can be used to convert Java Objects into their JSON representation. It can also be used to convert a JSON string to an equivalent Java object ● Simple toJson() and fromJson() methods to convert Java objects to JSON and vice-versa ● Extensive support of Java Generics ● Allow custom representations for objects ● Support arbitrarily complex objects (with deep inheritance hierarchies and extensive use of generic types) Vladimir Kotov Working in the Background 33
  • 34. JSON Parsing with GSON Vladimir Kotov Working in the Background 34
  • 35. Workshop ● Purchase list synchronization Example http://kotov.lv/JavaguryServices/purchases/ ● Web-service (REST) vladkoto – https://github.com/rk13/java guru-services { – http://kotov.lv/JavaguryServ "My Purchase List":[ ices/purchases/ {"name":"Bread","quantity":"11"}, {"name":"Jameson Wiskey","quantity":"1"}], ● API "Mom Purchase List":[ – http://kotov.lv/JavaguryServ ices/purchases/{TOKEN} {"name":"Cranberry","quantity":"1kg"}, – GET / POST {"name":"Tomato","quantity":"2"}] } Vladimir Kotov Working in the Background 35
  • 36. Sync Purchase Lists ● Task1: Import purchase lists ● Use AsyncTask ● Load json from service ● Convert and display ● HttpTask.java for starting point ● Task2: Export purchase lists ● Use IntentService ● Convert and push json to server ● ExportService.java for starting point Vladimir Kotov Working in the Background 36
  • 37. Sync Purchase Lists ● Task3: Sync service configuration via preferences ● Task4: Export/Import adoption in Purchase list app Vladimir Kotov Working in the Background 37