cancelCleanUp
Cancel Cleaning Up Expired Temporary Files
The cancelCleanUp method is used to immediately interrupt the disk cleanup task currently in progress. Used together with cleanUpExpiredTemporaryFiles, it is an important flow-control means for ensuring application performance and responsiveness.
Method Declaration
/**
* Cancel the task of cleaning up expired temporary files
* After being called, the SDK stops the background thread that is scanning or deleting files as quickly as possible.
*/
void cancelCleanUp();Runtime Behavior
- Interrupt scan signal: After the call, the SDK sends an interrupt instruction to the background cleanup thread.
- Stop file iteration: The cleanup logic no longer reads the next entry in the file list.
- Finish current operation: If the SDK is performing the deletion of a specific large file, it usually waits for that atomic operation to complete before stopping.
- Callback termination: Once the task is cancelled,
CleanUpExpiredTemporaryFilesListenerno longer receives subsequentonRemoveoronSuccesscallbacks.
Use Cases
1. Business Priority Switching
When a background cleanup task is running and the user suddenly taps "Enter Game", this method should be called immediately to seize disk I/O resources and ensure game loading speed.
2. Lifecycle Protection
Call this when a component containing cleanup logic (such as an Activity or Service) executes onStop() or onDestroy(), to prevent memory leaks and unnecessary background resource usage.
3. System Resource Warning
If the app detects that the current system CPU or I/O load is too high, this method can be used to temporarily abort maintenance operations.
Example
// Ensure the cleanup task stops when the Activity is destroyed
@Override
protected void onDestroy() {
super.onDestroy();
if (mRuntime != null) {
// Interrupt any cleanup logic in progress
mRuntime.cancelCleanUp();
}
}
// Or proactively yield before starting a game
public void onUserClickStartGame() {
mRuntime.cancelCleanUp(); // Stop cleanup to free up disk I/O
mRuntime.createGameHandle(...);
}Notes
- Not reversible: This method can only stop "future deletions"; it cannot recover files that have already been physically deleted during the cleanup process.
- Non-blocking call: This method returns immediately and does not block the current thread while waiting for the background thread to fully terminate.
- Repeatable: If no cleanup task is running, calling this method produces no side effects or exceptions.
Disk maintenance logic is now complete. Would you like to continue organizing the specific population rules for each Key in the Bundle options parameter of createGameHandle?
