Posts

Showing posts from March, 2022

Background Work in Android Studio

Image
Overview You should not do blocking tasks on UI Thread. Such as decoding bitmap accessing storage working on machine learning model network request Definition of background work An app is running in the background when both the following conditions are satisfied: No activities of an application are currently visible to the user. When an application was visible to the user then that application didn't start any foreground services. Type of background work Approaches to background work Below figure can be used to guide which approach is used for a particular type of work/task. Immediate Work Immediate work encompasses tasks which need to execute right away. For persistent immediate work, you should use WorkManager with a OneTimeWorkRequest . Expedite a WorkRequest with setExpedited() . For impersistent immediate work, you should you use Kotlin coroutines. If your app uses the Java programming language, you should use RxJava or Guava . You can also use Executors . Long-Running Work