8. SDK Lifecycle — destroy()
The OctopusTMS SDK is a singleton that holds a connection to the hardware service. To prevent memory leaks and service connection leaks, you must call destroy() when the host Activity is destroyed.
destroy()
override fun onDestroy() {
super.onDestroy()
pos.destroy()
}
@Override
protected void onDestroy() {
super.onDestroy();
pos.destroy();
}
WARNING
After destroy() is called the singleton is null. Calling any SDK method after this will throw an IllegalStateException.
Singleton Lifecycle Flow
| Activity Event | SDK Action | Note |
|---|---|---|
| onCreate() | Call getInstance() | Creates or returns the existing singleton |
| onCreate() (after getInstance) | Call initialize() | Binds to hardware service, detects OEM |
| After initialize succeeds | Call downloadAndInjectKeys() | Downloads and injects terminal master keys |
| User action | Call startPayment() | Must be on main thread |
| onDestroy() | Call destroy() | Unbinds hardware service, clears singleton |