Supporting applications running Android services

Last updated:

This article provides details on supporting applications running Android services. The complexity in applications utilizing Android services is that when a user closes the app while a service is running, the application object stays live because it is still connected to the service.

This causes the Application:onCreate method not to be called if we reopen the app while a service is running, which causes the initialization code not to be called (as Pendo SDK initialization relies on the Application:onCreate method).

To ensure consistent behavior and data, use three APIs:

  1. 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.
  2. setup(...) - This API should be called from Application:onCreate. This API ensures we do the basic initialization the SDK needs. 
  3. startSession(...) - A session is restarted by calling the startSession() method. This API should be called from any context in the app, where you already have the VisitorID available. This is usually called from an Activity’s onCreate method.

End Session API

When you call the endSession method, the following happens:

  • The Visitor ID and Account ID are cleaned
  • No guides are shown
  • No analytics are sent

This API should be called in the service’s onTaskRemoved method.

public static void endSession()
Was this article helpful?
1 out of 2 found this helpful