Skip to main content
Version: v5

Conditional initializaton

You may want to remotely control whether the Incognia SDK should be initialized or not. It is not enough to avoid calling Incognia.init(Context context) in order to completely disable the Incognia SDK. You also need to call Incognia.disable(Context context) in your Application.onCreate() as shown below:

class CustomApplication : Application() {
  override fun onCreate() {      super.onCreate()
      if (YourRemoteConfig.isIncogniaSdkEnabled()) {          Incognia.init(this)      } else {          Incognia.disable(this)      }  }}

This is necessary because, upon initialization, the Incognia SDK activates APIs such as geofences, jobs, and alarms to be able to wake up in background and work as expected. Those mechanisms will auto-initialize the Incognia SDK even if a call to Incognia.init(Context context) isn't done in the Application.onCreate() method. By calling Incognia.disable(Context context), all alarms, jobs and geofences are removed. The SDK will cease any current background activity and won't auto-initialize. To re-enable the SDK, explicitly call Incognia.init(Context context) in the Application.onCreate() method.