Shutdown
In long-running React Native apps you usually never need to shut the SDK down — it can simply keep running for the lifetime of the process. However, in a few specific situations a clean shutdown is useful:
- On user logout, if you want to ensure the previous user's events are fully delivered before the next user signs in.
- During automated tests, where you want to reset the SDK between scenarios.
- Before swapping the SDK configuration at runtime — for example, switching between staging and production endpoints.
Calling destroy flushes any pending events, stops all background work, and returns the SDK to the uninitialized state. After destroy you may call init again with a fresh configuration:
// On user logout
await B2Metric.destroy()
// Later, when a new user signs in
await B2Metric.init({
apiKey: 'YOUR_API_KEY',
appIdentifier: 'your_app_identifier',
})
Calling destroy when the SDK has not been initialized is a no-op and does not throw. Calling other SDK methods after destroy but before the next init will throw an error — the SDK explicitly enforces an initialized state for all tracking methods.