I'm getting started with Google's C2DM. Part of this process involves receiving a Broadcast Intent when registration has occurred. In Google's official C2DM documentation, the example code shows the following comment in the BrodcastReceiver's onReceive() method:
// Send the registration ID to the 3rd party site that is sending the messages.
// This should be done in a separate thread.
However, everything I've read, including the documentation for BroadcastReceiver, suggests that starting a thread from onReceive() will almost certainly cause problems, because as soon as onReceive() has returned, the process will likely soon be killed.
It's possible that someone just made a mistake, and that I should just disregard the comment about using a separate thread, but I'm guessing there's a reason they said it, even if it's misleading.
Is there a reason one can't or shouldn't use the network from the same thread as onReceive() before returning? If doing so is problematic, what's the proper way to handle what must be a common situation, even outside of C2DM? Starting a Service?
AsyncTask
is not appropriate here. Basically any asynchronous operation is inappropriate foronReceive()
. Take a look atonReceive()
documentation for details. Your best bet is to start aService
which initiates the network communication. – Rupture