asynctask-to-executor
Installation
SKILL.md
Migrating AsyncTask to ExecutorService / WorkManager
Instructions
AsyncTask has been deprecated since API 30. It leaks Activities, serializes tasks globally on older devices, and has no structured cancellation. Replace it with either a scoped ExecutorService + Handler or WorkManager depending on the use case.
1. Decision Tree
- Short-lived, tied to a screen (load, parse, save on click) →
ExecutorService+ViewModel. - Deferrable, must run even if the app dies (upload, sync) →
WorkManager. - Reactive pipeline with cancellation-on-recycle → RxJava 3 (see
rxjava3skill).
2. Pattern: In-Activity AsyncTask
Before: