Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
829 views
in Technique[技术] by (71.8m points)

firebase - Android Notification with FCM - Who started the FirebaseMessagingService?

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:

  1. Who started the FirebaseMessagingService notification service? There must be some place calling startService(), isn't it?

  2. 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:

  1. 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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...