2

In my Xamarin app, I have implemented code to receive silent background notifications which is sent every 30 minutes. Everything works fine except on new Samsung devices (Galaxy S7, S10 etc.) the application receives the first notification and processes it, but the second notification and the other ones that is sent half an hour after the previous notification, are ignored by the device and a message is shown on the device saying the application is draining battery and has frequently crashed.

By checking the logs I can see the function which receives the incoming notifications is running for the first notification but is not running for the other incoming ones, which means the problem is not from the code itself.

Anyone knows what the problem is caused by?

Below I have given a short view of my function that receives the notification:

  public async override void OnMessageReceived(RemoteMessage message)
    {

        Log("This is logged only first time when app is in background");

            //if the message does not contain a type then print out the message only
            if (String.IsNullOrEmpty(message.Data["type"]))
            {
                SendNotification(message.Data["message"], "MyApp");
                return;
            }

            string messageType = message.Data["type"];

            switch (messageType)
            {
                case "CheckUserGPS":
                  //checks the users gps and updates the user in server
                  .....
                    break;
            }

    }
DA_VDCT
  • 19
  • 6

1 Answers1

1

At what point your app is crashes and what type of services you are using for notifications. Some of the link is given below that may be help you. 1. https://forums.xamarin.com/discussion/92877/android-app-crashes-after-receiving-push-notification 2. https://github.com/xamarin/Xamarin.Forms/issues/5339 3. Xamarin Notification Android Crash

  • 1
    Thanks. I didn't find a proper solution. I believe my problem might be because of the Android version that Samsung uses, not the implementation itself really – DA_VDCT Jan 17 '20 at 15:53
  • I am facing a similar problem for my Android app (built with Android Studio). My app checks for birthday at 12 am everyday in background. Samsung suddenly displayed that this app is using battery in the background. When I clicked on that notification, it showed that the app has frequent crashes. I have used **try...catch** as well as Logcat but no error has been detected so far. But the problem is, how can I limit the battery use of my app? – Samudra Ganguly Apr 21 '22 at 11:59