Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Background Task with WorkManager.pdf

Adi Nugroho
September 24, 2019

Background Task with WorkManager.pdf

Introduction to Background Processing and WorkManager in Android App Development.

Adi Nugroho

September 24, 2019
Tweet

More Decks by Adi Nugroho

Other Decks in Programming

Transcript

  1. Background Processing ◉ Android has main thread, which handles UI

    & user interaction. ◉ Too much process on main thread = lag / froze even forced close. ◉ Solution #1 Background thread = move the processing in background while the app is active. ◉ Solution #2 Background process = move the processing in background even though the app is not active.
  2. Type of Background Processing - Service - Job Scheduler -

    Alarm Manager - Foreground Service - WorkManager
  3. Foreground Service - Service but run in Foreground. - Shows

    unclearable notification. Place your screenshot here
  4. How to Choose The Right Background Processing? - https://developer.androi d.com/guide/backgroun

    d - Deferrable - put off (an action or event) to a later time; postpone
  5. WorkManager - Part of Android Jetpack. - Backwards compatible (~

    API 14). - Uses JobScheduler on API 23+. - Uses a combination of AlarmManager & BroadcastReceiver on API 14-22. - Ensures task execution, even if the app or device restarts.
  6. WorkManager - Schedule one time task or periodic tasks. -

    Constraints. - Chaining. - Manage & monitor scheduled tasks. - Works with or without Play Services. - Adhere to system best practices. - LiveData support.
  7. Chaining - Multiple requests can run in sequence. - A

    request output become next request’s input. Request #1 Get Location Request #2 Send to Server Request #2 Check Location
  8. Case for WorkManager - Sending logs / analytics / data

    to server. - Periodically update user location. - Sync data with server. - Create local notification after certain time has passed.
  9. WorkManager APIs Worker This is where you put the actual

    work to be executed. You’ll extend this class and override the doWork() method.
  10. WorkManager APIs WorkRequest Represents the request to do the work.

    It consists of OneTimeWorkRequest and PeriodicWorkRequest. You passed in a Worker to create a WorkRequest. You can also set the Constraints or a Delay.
  11. Any questions ? You can find me at ◉ @adinugroho

    ◉ https://t.me/kelasmobilemalang Thanks!