Is FirebaseMessagingService
onMessageReceived
called on main or background thread?
Asked
Active
Viewed 1,857 times
3
-
Its called on the main thread – tyczj Nov 21 '17 at 18:50
-
1@tyczj How do you know that? – Don Box Nov 21 '17 at 21:53
-
@tyczj Do you have a link or anything? FirebaseMessagingService derives from Service so I really don't know what it is doing – Don Box Nov 21 '17 at 21:54
-
1You seem to be wrong: https://stackoverflow.com/questions/41067081/does-firebasemessagingservice-run-in-the-background-by-default – Don Box Nov 21 '17 at 21:55
1 Answers
1
It runs asynchronously with the main thread as it may take some time to download the message which can help in avoiding frozen activity for better user experience.

Rahul Mishra
- 583
- 7
- 17
-
It's a `Service`, it runs on the service thread. `FirebaseMessagingService` has it's own process id. – Nikola Despotoski Nov 22 '17 at 00:59
-
that still doesn't answer my question whether the `onMessageReceived` is called on main or background thread – Don Box Nov 22 '17 at 06:37
-
As suggested by Nikola, onMessageRecieved is called by the service when the messge is received. And it runs on separate thread asynchronously which you are referring as background thread. – Rahul Mishra Nov 22 '17 at 08:03
-
-
1@DonBox, checkout my answer here: https://stackoverflow.com/a/41067993/2371425 – Sakiboy Feb 21 '18 at 05:15
-
Thanks @Sakiboy ! If you add an answer here I will mark it as solution – Don Box Feb 21 '18 at 11:07
-
@DonBox, it’s alright, the other question/answer has been linked in here a couple times, so people will find it. I don’t want to spam or post duplicate answers. – Sakiboy Feb 21 '18 at 11:10