Topics: Background Optimizations, Implicit Broadcast, Android, Software
Transcript Summary: The importance of background optimizations and connectivity change in Android development patterns. Background Optimizations allows Android applications to run on low-memory devices, or in low-memory conditions, that can improve performance and user experience.
Modern Android devices have lots of applications with background optimizations, however it can be problematic when each of the services run over the user’s processor. In a low memory situation, there are often a number of background optimizations running, without enough memory for all of them. When this happens, the operating system must swap a lot of processes in and out of RAM, known as memory thrashing. This reduces the overall system performance, which manifests as poor performance for the application. The reason that many background optimizations trigger at once is because it is a response to an implicit broadcast. An implicit broadcast is a trigger that declares an event instead of calling a specific application, meaning that there is a reasonable use case of passing some data along to another application to do a task. Most applications have a static receiver declared in their manifest to listen for these, which means the application isn’t even running when it gets the broadcast for this event. This results in the application waking up solely for the opportunity to respond with the worst case being an application woken up to look at the event. This will also conclude that the application wasn’t interested in the event with several precious RAM cycles wasted. On some devices, there are more than forty applications that wake-up. This could mean hundreds of wake-ups in a few minutes; therefore, crippling device performance. The ability to remove connectivity change as well as a few other broadcasts is a solution to solving the wake-up issue due to the fact that an application isn’t a bad actor while solving an issue within the platform.
Connectivity change will no longer wake applications that are targeting in if you
declared a static receiver in the manifest. If your applications is already running and you’ve
registered your receiver, you can still receive this implicit broadcast, but you will not wake up for it. If a user has some work that needs to be done based on the connectivity change
and regardless of whether the application is running, you’ll want to schedule a job with JobScheduler or Firebase. Use JobDispatcher for the network conditions you truly care about instead of passively listening, waking, and then checking to see if the connectivity change was the right change for you. When your application uses JobScheduler and everyone else’s applications start using it, the system can batch all of those jobs, leading to a much more stable situation overall. Another situation that involves applications is with NEW_PICTURE and NEW_VIDEO. This is a critical user experience moment because slowing down the camera by waking all these applications can destroy the camera experience causing users to miss the moment. These broadcasts aren’t sent by the system, but by applications such as a camera. It is important to know that these two changes are not specific for applications targeting NuGet as these applications are deprecated in API 24. JobScheduler would be an alternative to this as it considers content provider changes as a trigger.