Starting FCM services at boot without activity

I followed the Firebase Quickstart Messaging Tutorial and I have a problem.

I would like to start two services ( MyFirebaseMessagingService and MyFirebaseInstanceIDService ) at system startup.

To do this, I added the RECEIVE_BOOT_COMPLETED permission to my AndroidManifest.xml .

I also added this to the manifest :

 <receiver android:name=".AutoStart"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> <action android:name="android.intent.action.QUICKBOOT_POWERON" /> </intent-filter> </receiver> 

My AutoStart class has the following:

 @Override public void onReceive(Context context, Intent intent) { context.startService(new Intent(context, MyFirebaseInstanceIDService.class)); context.startService(new Intent(context, MyFirebaseMessagingService.class)); } 

The two services are almost the same as in the links I cited above. And my MainActivity contains only a few Views .

But this does not work: as soon as the services start, the services are automatically killed, and I get this message in logcat:

 I/ActivityManager﹕ Killing 3100:com.company.E/u0a85 (adj 15): empty #17 

I was looking for solutions to this "murder issue" and I think I found something interesting here (about the WakefulBroadcastReceiver ).

If this part of the solution, I met another problem with this answer ... the onHandleIntent() override method that he talks about is part of the IntentService , where my two services are Service .

If this is not part of the solution, I don’t know how to prevent my application from being killed ...

+5
source share

All Articles