Android एक कठोर threading model आहे जो main (UI) thread च्या भोवती केंद्रीत आहे — ज्याने UI हाताळणे आणि प्रतिक्रिया देणे आवश्यक आहे. Threading समजून घेणे, कार्य main thread च्या बाहेर का हलवायचे हे जाणणे, आणि साधने (coroutines, आणि ऐतिहासिकदृष्ट्या threads/handlers) हे उत्तरदायी apps साठी महत्वाचे आहे.
main thread नियम
Android has a single MAIN (UI) thread that:
→ handles ALL UI operations (drawing, events) — UI updates MUST happen on it
→ must stay RESPONSIVE — blocking it freezes the UI; >5s blocked = ANR (App Not Responding)
TWO key rules:
1. DON'T do long/blocking work on the main thread (network, DB, heavy compute) → move it off
2. DON'T update UI from a background thread → switch back to the main thread for UI
