Best practices for the Awareness API

  • The Awareness API lets your app react to user context changes, but it's crucial to use it responsibly to avoid negative user experiences.

  • Manage user expectations by clearly indicating how your app will utilize the Awareness API and what actions it might trigger.

  • Minimize notifications and ensure they are relevant to the user to prevent notification overload and maintain a positive user experience.

  • Be aware of the Awareness API's potential impact on battery life and avoid excessive fence registrations or snapshot requests.

  • Utilize the Awareness API primarily for context-aware features and consider alternatives like JobScheduler for non-time-sensitive tasks.

The Awareness API gives you the power to react to changes in a user's context, but with this great power comes great responsibility. In order to provide an optimal experience for your users, consider the following guidelines.

Be mindful of user expectations
Be sure the user understands what to expect from your app. For example, suppose your app is designed to instantly play music when the user plugs in their headphones. This could result in a bad experience if the user doesn't expect such behavior.
Be conservative with notifications
If your app sends notifications, clearly communicate this to the user. Send only notifications that are relevant to the user. Keep in mind that your app must coexist with many other apps that might also send notifications.
Conserve system health
Although great effort was spent to make the Awareness API efficient, it still has the potential to consume significant amounts of battery life if used carelessly. The Awareness API manages system health for you. However, if you register too many fences, the Awareness API throttles callbacks to prevent undue battery drain. Likewise, excessive snapshot requests can also drain battery life.
Use the Awareness API for awareness
If your app needs to perform tasks that aren't time-sensitive, such as data synchronization or cleanup operations, consider the JobScheduler API to perform such tasks.