Noob question, is there a main thread per app? Or ...
# android-architecture
Noob question, is there a main thread per app? Or a single one for the whole OS ui? i.e. do I lag the whole phone if I do blocking stuff on main thread in Service (running the my app ui is in background)?
The main thread is scoped to your app. Even if you block the UI thread, the user can still press home or change apps.
Ok so if I do crappy blocking stuff in my Service which is lets say a music player, I won’t interfere with launcher animations. i.e. the only thing I really risk is getting ANR dialog?
Your Service is part of your app. Blocking the main thread in your Service will cause jank in your Activities. There's one main thread per process. By default, all your components (Activities, Services, BroadcastReceivers, etc) in that process use that main thread (unless you explicitly kick off background threads/schedulers/dispatchers.
đź‘Ť 3
But other apps won't be affected, since they'll be running in different processes
If you block the main thread you will get an “application not responding” error, so you want to avoid that at all costs. Each application runs in its own process. Be careful with app death, the OS can kill your process if it needs to divert resources elsewhere (like if your app is paused and you start running a game)
Im aware, I was just wondering what does effectively happen when Service blocks main thread when my Activity is in background (user is doing something else in some other app) So basically nothing (unless I block it for too long and get ANR dialog) thanks!
This isn’t Kotlin related, so I won’t follow-up any more on this, but I’d definitely re-read the docs.
Its just a thought exercise really. To get ANRed you have to block for consecutive seconds. If you just do sql writes for 50ms, you wont jank others apps ok thanks for ypur help!