LogoLogo
Insights
  • Introduction
  • A standard integration
  • FAQ
    • FAQ
      • Integration (FAQ)
      • Detections (FAQ)
      • Data interface (FAQ)
      • Security, Privacy and Terms of Service (FAQ)
      • Journeys and Insights (FAQ)
  • SDK
    • Getting Started
      • Android Quick Start
        • 1. Android Checklist
        • 2. Including the SDK
        • 3. Configuration
          • Sample Notification
        • 4. Initialization
        • 5. Starting Detections
        • 6. SDK Status Updates
        • 7. Permissions
        • 8. What's Next
      • iOS Quick Start
        • 1. iOS Checklist
        • 2. Installation
          • Installation with CocoaPods
          • Installation with Carthage
          • Manual Installation
        • 3. Configuration
          • Using Integration Guide
          • Manual Configuration
        • 4. Usage
        • 5. Tips and Guidelines
        • 6. What's Next
      • React Native Quick Start
        • 1. React Native Checklist
        • 2. Installation
        • 3. Configuration
        • 4. Initialization
        • 5. Usage
        • 6. What's Next
    • Appendix
      • Android
        • Android 10 Update Behavior
        • Android Battery Optimization
        • External SDK Dependencies
        • Manifest Permissions
        • Notification Management
      • iOS
        • App Store Privacy Section
        • App Store Release
        • iOS 13 permission changes
        • M1 Simulator Support
        • Swift Support
      • Control Sending Data
      • Controlled Detections
        • Automatic Detections
        • Automatic Detections with Forced Trips
        • Controlled Trips Only
        • Checking Trip Status
      • Custom User Metadata
      • Detecting Vehicle Crashes
      • Migration Guide
        • Android
        • iOS
      • React Native
      • SDK Initialization
      • User Credentials
      • User Linking
      • Xamarin
    • API Reference
      • Android
        • VehicleCrashDetection
          • VehicleCrashEvent
          • VehicleCrashListener
          • CrashCallback
        • InitState
        • MetaUserLinker
        • MetaUserLinkerAsync
        • MetaUserLinkerCallback
        • OnInitCallback
          • InitIssue
        • OnSdkStatusUpdateHandler
        • OnStartFinishedHandler
        • PoiAddress
        • PoiLocation
        • PointOfInterest
        • PoiPlace
        • ResetCallback
          • ResetFailureReason
        • SdkConfig
          • Builder
        • SdkException
        • SdkStatus
          • LocationSetting
          • Quota Status
          • StartStatus
        • Sentiance
        • SubmitDetectionsCallback
        • StationaryInfo
        • Token
        • TokenResultCallback
        • Trip
          • StartTripCallback
          • StopTripCallback
          • TransportMode
          • TripTimeoutListener
          • TripType
        • TripInfo
        • TripProfile
          • HardEvent
          • TransportSegment
          • VehicleMode
        • TripProfileConfig
          • Builder
        • TripProfileListener
        • UserActivity
        • UserActivityListener
        • UserActivityType
      • iOS
        • MetaUserLinker
        • SENTSDK
          • SENTSDKStatus
          • SENTPublicDefinitions
        • SENTConfig
        • SENTTripProcessingTripProfile
          • SENTTripProcessingTransportSegment
          • SENTTripProcessingHardEvent
          • SENTTripProcessingVehicleMode
        • SENTVehicleCrashEvent
      • React Native
    • Battery Optimization
    • How To
      • Check the Location Permissions
    • Troubleshooting
      • Android
      • iOS
        • Bundle format unrecognized, invalid, or unsuitable
        • Error: Undefined symbols for architecture arm64
    • Changelog
      • Android
      • iOS
  • Important topics
    • Authentication and Authorization
    • User linking
    • PlayStore Location Access Review
    • Privacy Report & Dashboard
    • Vehicle Crash Detection
  • Library
    • Events
    • Moments
    • Segments
    • Glossary
  • Backend
    • GraphQL
    • REST API Reference
      • Error Codes (REST API)
    • Offloads
    • Data Reference
      • Data Reference A-B
      • Data Reference C-G
      • Data Reference H-L
      • Data Reference M-P
      • Data Reference Q-T
      • Data Reference U-Z
  • Data Explorer
    • Data Explorer
      • Global (EU)
      • US
      • Australia
  • Guide
    • Firehose
    • Verifying your integration
    • SDK Standard License
    • Journeys License
    • Journeys Application
    • Journeys Privacy Policy
    • Technical & Organizational Measures
Powered by GitBook
On this page
  • What Does Initialization Do?
  • Why Initialize in the Application / AppDelegate Class?
  • Initialization Must be Done Only Once
  1. SDK
  2. Appendix

SDK Initialization

PreviousReact NativeNextUser Credentials

Last updated 1 year ago

This document refers to deprecated parts of the platform and has been left intact to help customers with legacy integrations. In order to access the latest platform features and documentation, please go to https://docs.sentiance.com.

What Does Initialization Do?

During initialization, the Sentiance SDK will construct all the components necessary to do detections, networking, and maintenance work.

The first time the SDK is initialized, a unique ID will be assigned to the device. All detections made on this device will be tagged with this ID as they get uploaded to the server to create a user timeline. Additionally, a configuration will be loaded from the server to determine detection parameters like location request intervals, sensors to record, and sampling rates. Last but not least, the SDK will schedule jobs and alarms for purposes of uploading data to the server and performing internal maintenance.

Subsequent initializations will ensure the SDK components are constructed and ready to handle incoming broadcast intents and alarms.

Why Initialize in the Application / AppDelegate Class?

Once the Sentiance SDK has been initialized, it will set jobs, alarms, and geofences as part of the detection process. When your app is not running and a geofence event occurs, the system will start the process and deliver the broadcast intent or notification directly to the SDK. Therefore, the SDK must already be initialized before handling this event.

Initializing the SDK in the onCreate() or didFinishLaunchingWithOptions method of your Application / AppDelegate class will ensure the SDK components are constructed, since these methods are guaranteed to finish before an intent or a notification is delivered to any broadcast receiver / delegate function.

The only exception to the above rule is the first ever SDK initialization call. This can be delayed since the SDK has not yet set any alarms, geofences, etc. A good reason to delay this first call for example, is when you need to download the Sentiance credentials from a remote server, or you need to handle a first user login.

Another important consideration is that when initializing inside onCreate() and didFinishLaunchingWithOptions, it must be done synchronously on the main application (UI) thread. When onCreate() or didFinishLaunchingWithOptions is finished, init should have already returned. Therefore, using DispatchQueue.main.async or Handler.post(Runnable) is not permitted.

On Android, when the SDK detects improper initialization, it will output the following error to logcat: "SDK is not initialized. Make sure to call Sentiance.init() in your Application.onCreate() method."

Initialization Must be Done Only Once

You should only ever call or initWithConfig if the SDK has not been initialized. Calling these methods more than once will throw an or NSException. This is intentional to guarantee single execution of the logic you've implement in the success method of your initialization callback.

To check whether the SDK has been initialized, call getInitState. This will return one of the following enums:

  • SENTInitialized

  • SENTNotInitialized

  • SENTInitInProgress

  • INITIALIZED

  • NOT_INITIALIZED

  • INIT_IN_PROGRESS

SdkException
init()