In the Firebase docs, it is safe to subscribe to a topic when your app is opened like in the MainActivity's onCreate.
MainActivity.java
FirebaseMessaging.getInstance().subscribeToTopic("announcement");
Most likely you'll receive your notification when the application is in background(Pressed the Home Button)/ Foreground.
Problem is when I closed the application (app is destroyed) or I've rebooted my phone, my app doesn't seem to receive the notification from Firebase Console(send via Topic). Though I think I need to implement a broadcast receiver when phone reboots.
Anyway I'm subscribed to the Topic from onCreate of my extended FirebaseMessagingService but it always calls onDestroy though. From debugging it seems that when a notification is received from a FirebaseMessagingService it goes to onCreate -> onMessage -> onDestroy for EACH notification.
As I understand my extended FirebaseMessagingService should live even if the app is destroyed so it shouldn't call onCreate every time.
Since a service should work even if the app is destroyed
So I'm wondering where should I placed my subscription to topic in my Android Code such that even if the app is destroyed it will still receive notifications like announcements.
Thank you in advance.