This article provides details on supporting applications running Android services. The complexity in applications utilizing Android services is that when a user closes or kills the application, while a service is running, the application object stays alive due to its connection to the service.
This causes the Application:onCreate method not to be called if we reopen the app while a service is running, this causes our initialization code to not be called (as Pendo SDK initialization relies on the Application:onCreate method).
To ensure consistent behavior and data, you need to use three APIs:
- endSession() - This API when called from the service’s onTaskRemoved() method, ensures the session is cleaned when the app is being closed by the user.
- setup(...) - This API should be called from Application:onCreate. This API ensures we do the basic initialization the SDK needs.
- startSession(...) - This API should be called from any context in the app, where you already have the visitor id available. (Usually called from an Activity’s onCreate method)
End Session API
This API should be called in the service’s onTaskRemoved method.
public static void endSession()
Frequently asked questions
What happens when you call endSession method?
- The Visitor ID and Account ID are cleaned
- No guides are shown
- No analytics are sent
How do I restart the session?
A session can be restarted by calling the startSession() method.