How to recieve FCM notifications when the app force-closed

Hello!
Please advice, I followed the tutorial and created Xamarin.Forms application to recieve FCM notifications.
It works perfectly when the app is running or backgrounded. If I force-close the app (e.g. press the Recent Apps button, and swipe away my app) and then send a push notification, the device shows this error message: "Unfortunately, [App_Name] has stopped".
According the tutorial :
If you force-close the app, FCM will stop delivering notifications. Android prevents background service broadcasts from inadvertently or unnecessarily launching components of stopped applications.

How to recieve FCM notifications when the app force-closed?
Thanks for your reply!

Posts

  • AlexPAlexP Member ✭✭

    I'm not too familiar with FCM, but my first guess would be to create a dedicated service to listen to your messages.
    You can have a look at this page: Create a service (In Xamarin.Android)
    This is the official documentation on how to create a service in Xamarin.Android.

    Sadly, since each platform handles background processes differently, there is no cross platform solution for it. You will have to implement it for each platform independently. A quick search in Google will reveal also a way to do so in iOS.

    P.S
    Here is a nice video by @RobGibbens on running background tasks.

  • When app force-closed I get an exception in device log:
    System.InvalidOperationException: You MUST call Xamarin.Forms.Init(); prior to using it.

    Xamarin.Forms.Init(this, bundle);is called in Android's MainActivity which hasn’t been yet instantiated when the code is executing the [Application] class.
    How can call Xamarin.Forms.Init() in my Android class [Application] OnCreate() ?

Sign In or Register to comment.