I have connected my project to firebase and I want to receive notifications on this app even if closed, in background, foreground or killed. I have made one button, when clicked it will subscribe user to the news topic, so can anyone please tell me that is this correct way to make a topic ?
public void onClick(View view){
FirebaseMessaging.getInstance().subscribeToTopic("news");
}
Here's what the docs say :
Based on the publish/subscribe model, FCM topic messaging allows you to send a message to multiple devices that have opted into a particular topic. You compose topic messages as needed, and FCM handles routing and delivering the message reliably to the right devices.
For example, users of a local weather forecasting app could opt into a "severe weather alerts" topic and receive notifications of storms threatening specified areas. Users of a sports app could subscribe to automatic updates in live game scores for their favorite teams.
So calling subscribeToTopic is the correct way to subscribe the user to the Messaging Topic. You need to also extend the FirebaseMessagingService overriding onMessageReceived and onDeletedMessages.
The case when the app is in foreground or background: