3

Is FirebaseMessagingService onMessageReceived called on main or background thread?

Neil
  • 14,063
  • 3
  • 30
  • 51
Don Box
  • 3,166
  • 3
  • 26
  • 55

1 Answers1

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
  • Do you have a reference where I can be sure this is how it works? – Don Box Nov 22 '17 at 09:08
  • 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