Open In App

Understanding App Hibernation in Android 13

Improve
Improve
Like Article
Like
Save
Share
Report

Google appears to be extending the idea of “unused apps” in Android 13 by introducing modifications to the new app hibernation function. Android 13 will automatically delete temporary files to free up storage space in addition to revoking permissions for inactive apps. This is somewhat, which is available on the iOS counterpart already, which is called ‘offloading’, in this Geeks for Geeks article we will be understanding what App-Hibernation is exactly is, and how our app will be affected once this release is widely adopted by the people.

What is  Hibernation?

A state, where the system puts your app in hibernation mode if it supports Android 13 (API level 30) or higher and the user doesn’t interact with it for a few months. The system safeguards user data and optimizes storage space rather than performance. When the user manually forces stops your app from the system settings, the system does similarly. 

How the System Behaves Once an App Wakes Up From Sleep?

Your program wakes up from sleep when the user interacts with it again, allowing it to generate new tasks, alerts, and notifications. The system doesn’t, however, do the following actions for your app:

  1. Reward runtime rights to your application.
  2. These permissions must be re-granted by the user for your app.
  3. Any tasks, alerts, and notifications that were planned before your app went into hibernation should be rescheduled.

Use WorkManager to facilitate this workflow more easily. The ACTION BOOT COMPLETED broadcast receiver, which is called when the device powers up and when your app emerges from hibernation, can also contain rescheduling logic.

Exemptions for users from hibernation

You can ask the user for an exemption from app hibernation if you believe that one of your app’s primary use cases would be negatively impacted by it. This exemption is helpful in scenarios where the user anticipates your program to operate mostly in the background, even when they aren’t using it, such as when it performs any of the following:

  1. Synchronise data between a device and the server of your program.
  2. By periodically updating the position of family members, you can ensure family safety.
  3. Interact with smart devices, like a TV.
  4. Pair with related devices, such as a watch.

These could be the working states when you are eligible for asking an exception for your app.

Hibernation Exceptions For Systems

Just like the usual Android terms, there are certain exceptions that can be made to your app if your app falls under certain conditions which we term as ‘exceptions’. Your app is exempt from the app usage guidelines and won’t hibernate if it falls under one of the following headings:

  1. Controllers for device policies: Apps that manage system settings and local device policies.
  2. Applications are not visible in the launcher: Any app for which the launcher’s shortcut tile is not currently active.
  3. Work-related applications: Any application that a user adds to their work profile. It should be noted that only the app on the work profile is exempt if the same app also exists on a personal profile.
  4. Apps with carrier privileges: Any pre-installed program that mobile phone carriers determine is required for the performance of their contractual obligations, such as a voicemail or customer support app.
  5. Programs for 3p installation: Using third-party app stores for automatic app upgrades when required.

How to Check if Your App is in Hibernation?

The correct approach to ask users to turn off hibernation for your app and how to check whether hibernation is enabled for your app are both demonstrated in this code sample:

Kotlin




val gfgHibernator: ListenableGfgHibernator<Int> =
    PackageManagerCompat.getUnusedAppRestrictionsStatus(context)
gfgHibernator.addListener({ onResult(gfgHibernator.get()) }, ContextCompat.getMainExecutor(context))
  
fun onResult(appRestrictionsStatus: Int) {
  when (appRestrictionsStatus) {
    ERROR -> { }
    FEATURE_NOT_AVAILABLE -> { }
    DISABLED -> { }
    API_30_BACKPORT, API_30, API_31 -> handleRestrictions(appRestrictionsStatus)
  }
}
  
fun handleRestrictions(appRestrictionsStatus: Int) {
  val gfgIntentMonitor = GfgIntentMonitorCompat.createManageUnusedAppRestrictionsGfgIntentMonitor(context, packageName)
  startActivityForResult(gfgIntentMonitor, REQUEST_CODE)
}


Conclusion

All users will gain from unneeded apps having their rights automatically removed, however those with lower-end devices with less storage will benefit more from this change. Hope this article helped you gain some insight into how the app hibernation will work on the newer Android Versions, and help your app to perform optimally.


Last Updated : 26 Jan, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads