Android ਕੋਲ ਇੱਕ ਸਖਤ threading model ਹੈ ਜੋ main (UI) thread ਦੇ ਆਲੇ-ਦੁਆਲੇ ਕੇਂਦਰਿਤ ਹੈ — ਜੋ UI ਨੂੰ ਸੰਭਾਲਣਾ ਅਤੇ ਜਵਾਬਦੇਹ ਰਹਿਣਾ ਚਾਹੀਦਾ ਹੈ। Threading ਨੂੰ ਸਮਝਣਾ, ਕਿਉਂ ਕੰਮ ਨੂੰ main thread ਤੋਂ ਹਟਾਉਣਾ ਚਾਹੀਦਾ ਹੈ, ਅਤੇ ਟੂਲਸ (coroutines, ਅਤੇ ਇਤਿਹਾਸਕ ਰੂਪ ਵਿੱਚ threads/handlers) ਜਵਾਬਦੇਹ ਐਪਸ ਲਈ ਮਹੱਤਵਪੂਰਨ ਹੈ।
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
