I have an Alarm go of using BroadcastReceiver, but I am a little confused on Threads. I would like to have it run on a separate thread so it doesn't cause unresponsiveness to anything else, but when looking on the Android Docs, I still don't really know if there is only one Main thread, or each application has its own Main thread.
For example, if my application isn't running, what would the point of running a separate thread in the BroadcastReceiver if each application runs its own Main thread, meaning I wouldn't be affecting the users' other processes. Since mine wasn't running, havent it do its thing wouldn't hurt. But in contrast, if there is one Main thread for all applications then I would need to move the actions to a separate thread. I hope I am not asking a stupid question. I just want to understand it thoroughly. Thanks in advance.
After some browsing around the Android Developer page, I believe that BroadcastReceivers run on the Main IO thread.
BroadcastReceivers have the function goAsync that allows
the implementation to move work related to it over to another thread to avoid glitching the main UI thread due to disk IO.
Source
Basic rule of android is, all the components of android runs in Main thread (UI thread) by default.
Broadcast receivers are very light weight components of android, which has to do its functionality with in maximum of 10 seconds (as per android documentation).
Since you want to kick off an alarm from receiver, I don't think it is really going to have serious effect on your UI responsiveness for the user. So it is not really required to start a different thread just to kick off the alarm from your receiver.
Ref taken from developer android
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With