13

I've followed the Firebase Quickstart Messaging Tutorial, and I've a problem.

I'd like to launch the two services (MyFirebaseMessagingService and MyFirebaseInstanceIDService) on the boot of the system.

For that, I've added the RECEIVE_BOOT_COMPLETED permission to my AndroidManifest.xml.

I've 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>

In my AutoStart class, there is this :

@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 nearly the same as on the links I've provided above. And my MainActivity only contains a few Views.

But it doesn't work : as soon as the services are launched, the services are automatically killed and I get a message like this in the logcat :

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

I've searched for solutions about this "killing problem", and I think I've found something interesting here (about WakefulBroadcastReceiver).

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

If this is not part of the solution, I don't know how to prevent my app to be killed...

Community
  • 1
  • 1
Drarig29
  • 1,902
  • 1
  • 19
  • 42
  • 9
    Once you define those services in your manifest with the correct filters, Google Play services (which will be started on boot) will start your messaging and Instance ID services for you. You don't have to start those services yourself. – Arthur Thompson Jun 23 '16 at 16:37
  • @ArthurThompson Ok but I've to start my app on boot to handle the notifications, right ? I'd like to be able to do stuff when a notification is received as soos as the phone has finished booting... After googling it, I don't find any example of what I'd like to do. – Drarig29 Jun 23 '16 at 21:18
  • 4
    You do not have to start your app on boot to handle notifications. Once Google Play services is installed on the device you will be able to receive notifications after boot. – Arthur Thompson Jun 24 '16 at 18:16
  • 1
    @ArthurThompson, do you have a source for that? Be it documentation or code. – aried3r Nov 07 '16 at 21:34
  • @Drarig29, did you able to solve this ? I have tried initialzing firebase app like FirebaseApp.initializeApp(context); , but it did not work – Tasneem Apr 05 '17 at 10:51
  • @Tasneem yes I did. Like Arthur Thompson said, my services are launched with Google Play Services, but not the application. In this project I only wanted to run some code when the notification was received... – Drarig29 Apr 05 '17 at 16:08
  • @Drarig29 but, in FCM service gets killed when user force stop the app then this action will never get called. – Tasneem Apr 05 '17 at 16:10
  • @Tasneem yes, but I don't know if the service will be restarted automatically or if it'll need a reboot... – Drarig29 Apr 05 '17 at 18:25
  • @Drarig29, nope the FCM service does not restart automatically if the app has been force stoped , user has to open the app again. – Tasneem Apr 06 '17 at 04:27
  • @Tasneem if the user wants to force your app, he'll do, and you can't restart it automatically, since it would contradict the user... This is the assumption I made for my app. – Drarig29 Apr 06 '17 at 10:35

0 Answers0