Is there an onMessageReceived background for the GcmListenerService?

When I extend the GcmListenerService , is it running onMessageReceived in the background, or is it in the user interface thread? I need to know if I can make network calls inside the body of a method without using asyncTask or such.

I looked at the source code and, of course, this is a vanilla service without handlers. But there is some code about THREAD_POOL_EXECUTOR and a number of obviously confusing things.

+6
source share
3 answers

A simple check to determine if the current thread is the main user interface thread

 boolean isMain = Looper.getMainLooper().getThread() == Thread.currentThread(); 

placed inside the onMessageReceived method, indicates that it works in the background process ( answer a similar question).

0
source

When I extend the GcmListenerService , does onMessageReceived work in the background process or is it in the user interface thread? I need to know if I can make network calls inside the body of a method without using asyncTask or such.

Yes, you can make network calls inside the onMessageReceived() method, because it works in the background. For example, you can load an image in this method before displaying it in a notification using the image notification style.

0
source

Services do not work in Ui / main thread.

The service can also start (in the background), even when the application is closed, so you can receive a push notification, listen to the intent that was triggered when you receive a push, and use it to wake up your application.

-one
source

All Articles