I'm trying to offload Firebase messaging into a standalone process in my app, different from the main app process. I've read
this blog by Doug Stevenson which says that Firebase is initialized by default in the main process of an application using ContentProviders (FirebaseInitProvider). And ContentProviders cannot initialize in any secondary process.
"ContentProviders aren't created in other processes, so you will have to manually init Firebase in your other processes in order to make use of Firebase features. I have not tried this myself yet, but my understanding is that you should do this via the FirebaseApp singleton using its initializeApp() function that takes three args. You'll need to arrange for this to happen at the entry point for your component that expects to run in another process. "
Here's what I tried:
I created a `FirebaseListenerService` which extends FirebaseMessagingService and added this to the manifest to come up in a secondary process:
<service
android:name=".xxx.yyy.FirebaseListenerService"
android:enabled="true"
android:process="secondary"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
In this FirebaseListenerService I override the onCreate function and initialize the FirebaseApp here:
@Override
public void onCreate() {
FirebaseApp.initialize(/** context */, /** options */);
}
I can see the "secondary" process starting up correctly.
I also see the onCreate() getting called.
However I do not see the FirebaseListenerService receive any messages via onMessageReceived()
I believe this should work in theory, but as Doug mentioned in the conversations before bringing up Firebase in a secondary process is not well tested, so I'm curious if it's some limitation within Firebase SDK itself that's causing this. Any help on this is really appreciated!