Well, after some research, I found this question , and the selected answer claims that onReceive()
works in the user interface thread. It did not occur to me, since this is the declared manifest receiver, as far as I knew, there was not a single user interface thread.
Since you cannot create networks in the Android UI thread, this answers the first part of my question:
- You both should not and cannot initiate network communication with
onReceive()
.
The fact that we are in a user interface thread is almost similar to ASyncTask , but the same as manually starting another thread. Thus, it seems that Service
is the only option.
source share