androiddude
androiddude

Reputation: 73

For GcmListenerService is onMessageReceived background?

When I extend GcmListenerService, is onMessageReceived running in a background process or is it on the UI thread? I need to know if I may make network calls inside the method body without using an asyncTask or such.

I looked at the source code and sure enough it is a vanilla service with no handlers. But there is a bit of code about THREAD_POOL_EXECUTOR and a number of apparently obfuscated stuff.

Upvotes: 7

Views: 1215

Answers (3)

Roee
Roee

Reputation: 1165

Services aren't running on the Ui / main thread.

Service can also run (in the background) even when the app is closed, this way you can get push notification, listen to the intent invoked when receiving the push and use it to wake your app.

Upvotes: -1

maohieng
maohieng

Reputation: 1736

When I extend GcmListenerService, is onMessageReceived running in a background process or is it on the UI thread? I need to know if I may make network calls inside the method body without using an asyncTask or such.

Yes you can make network calls inside onMessageReceived() method because it is running in a background process. For example, you can download an image in this method before displaying it on notification using big image notification style.

Upvotes: 1

gar_r
gar_r

Reputation: 347

Simple check to determine whether current thread is main UI thread

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

placed inside onMessageReceived method indicates that it is running in background process (answer to the similar question).

Upvotes: 0

Related Questions