For GcmListenerService is onMessageReceived background?
Asked Answered
M

3

7

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.

Malinda answered 15/3, 2016 at 19:40 Comment(0)
D
1

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.

Deactivate answered 3/1, 2017 at 5:57 Comment(0)
K
0

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).

Kala answered 24/8, 2016 at 15:49 Comment(0)
C
-1

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.

Coranto answered 16/3, 2016 at 0:10 Comment(1)
Methods are invoked asynchronously.Descendible

© 2022 - 2024 — McMap. All rights reserved.