destroy
Destroy Task Handle
destroy is a core method of the SUDOPGameTask interface. It acts as the "abort switch" for asynchronous tasks (such as game preloading, resource downloading, and environment initialization), used to immediately release the associated system resources when a task is no longer needed. When the Activity is destroyed or the user actively cancels loading, calling this method ensures that background tasks do not continue to consume memory and bandwidth.
Method Declaration
java
/**
* Cancels the currently running task and releases all associated hardware and memory resources.
* After this call, the task instance enters an invalid state.
*/
void destroy();Runtime Behavior
- Immediate interruption: The engine sends an interrupt signal to the underlying layer, stopping the current task's code logic execution and network I/O transmission.
- Resource reclamation: Triggers the underlying engine to release the occupied memory buffers, file handles, and temporary objects.
- State invalidation: Once called, the Task instance is declared discarded. Any subsequent operations attempted through this instance will be intercepted or ignored by the SDK.
- Silent destruction: The destruction process usually does not trigger the original task's "success" callback, but may trigger an error callback containing "cancelled" information.
Example Code
When an Activity or Fragment is destroyed, make sure to destroy the preload task promptly to save performance:
java
public class GameActivity extends AppCompatActivity {
private SUDOPGameTask mPreloadTask;
private void startPreload() {
// Start preloading and hold the handle
mPreloadTask = SudRT.getSDK().preloadGame("game_id_123");
}
@Override
protected void onDestroy() {
super.onDestroy();
// 1. If the task is still running, destroy it immediately
if (mPreloadTask != null) {
mPreloadTask.destroy();
// 2. Set the handle to null to prevent memory leaks
mPreloadTask = null;
}
}
}Notes
- Lifecycle binding: It is strongly recommended to bind the lifecycle of
SUDOPGameTaskto Android components (Activity/ViewModel) and perform destruction inonDestroyoronCleared. - Idempotency: This method supports being called multiple times. If the task has already been destroyed, calling
destroy()again produces no side effects and does not crash the app. - Thread safety: It can be safely called on either the UI thread or a worker thread; the SDK handles cross-thread state synchronization internally.
- Independence:
destroy()only targets the task represented by the current Task handle. It does not stop an already-running game instance or affect the global SDK state.
