This article is for Android Mobile 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).
In order to ensure consistent behavior and data, you will need to use three APIs:
- endSession() - This API when called from the service’s onTaskRemoved() method, will ensure the session is cleaned when the app is being closed by the user.
- setup(...) - This API should be called from Application:onCreate. This API will ensure 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()
What will happen when you call endSession method?
- The visitor ID and account ID will be cleaned
- No guides will be shown
- No analytics will be sent
How do I restart the session?
A session can be restarted by calling the startSession() method.