'How to use activity recognition Exemptions to start foregroundService from background?

Android 12 adds restrictions to launch ForegroundService from background, and the document mentions several Exemptions too. One of them is “Your app receives an event that's related to geofencing or activity recognition transition”. I cannot find any document to talk it in detail. Here are my questions.

  1. do I have to launch my ForegroundService immediately after I get this event? How long is the window?
  2. do I have to call startForegroundService(...) in the same thread as that the event from?
  3. do I need to pass some parameters from the event to launch my ForegroundService?

My device is Pixel 3a with Android 12



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source