According to the set up guide here, in a sample app, A) I created a class that extends
firebase services class. B) I put these classes in the AndroidManifest.xml
A) Java Class
public class MyFirebaseMessagingService extends FirebaseMessagingService {
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
//a) What's the life cycle of the service? How can I ensure this method is getting called?
//b) If the service is killed at some point, will system restart it on receiving new messages?
Log.d(TAG, "From: " + remoteMessage.getFrom());
}
}
B) AndroidManifest.xml
<service
android:name=".MyFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
Then, the app can receive notifications from FCM!
Here is my question:
Who started the FirebaseMessagingService notification service?
There must be some place calling startService(), isn't it?
My understanding is that, the downstream notification will deliver to my mobile device's google play service, regardless of the state of my app.
Then, to what extent can I ensure that my onMessageReceive()
is called when the app
or service
is swipe closed/killed/force stop
? Is the relevant behavior documented anywhere?
EDIT:
- I am more concerned about the following case. Let's talk about the
data message
. (compared to the notification message
.)
My client app received the FCM message and shows the default notification, because google play service is running and send it to the system tray. But my onMessageReceive()
is not called, because MyFirebaseMessagingService
is killed by system and not restarted. Is it possible?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…