detach
Detaches the SDK and stops all the work it may be doing. The SDK cannot be used after this method is invoked.
Overview
Call this method when you're completely done using the SDK to clean up resources and stop all background operations. After calling detach(), the SDK instance cannot be used anymore, and you must create a new instance by calling configure() again.
Syntax
fun detach()
Example
// Clean up SDK when done
override fun onDestroy() {
super.onDestroy()
// Detach SDK to release resources
sdk.detach()
}
// Example with try-finally for safety
fun cleanupSDK() {
try {
// Perform any final operations
saveState()
} finally {
// Always detach to clean up
sdk.detach()
}
}
// When switching to a different SDK instance
fun reconfigureSDK(newSiteId: String) {
// Detach old instance
currentSDK.detach()
// Create new instance
currentSDK = MaestroSDK.configure(
context = applicationContext,
maestroEventDelegate = this,
params = MaestroSDKParameters(siteId = newSiteId),
)
}
Notes
- Always call this method when you're done with the SDK
- The SDK instance becomes unusable after calling
detach() - This method stops all background work and releases resources
- Typically called in
onDestroy()or similar lifecycle methods - To use the SDK again, call
configure()to create a new instance - Multiple calls to
detach()on the same instance are safe
Related Methods
- configure() - Create a new SDK instance