GCM OnMessage() called randomly within the app without any push notification in Xamarin.Android

I am using GCM to receive PushNotification in my Xamarin.Android project. Whenever server has any updates it notifies the GCM and GCM in turn notifies the app, and everything is working as expected.

I have below code in OnMessage method.

    protected override void OnMessage (Context context, Intent intent)
        {

            if (intent != null && intent.Extras != null) {
                string dataFromServer = intent.GetStringExtra ("Updates from server");
                if (!string.IsNullOrEmpty (dataFromServer)) {
                    MainActivity.StartBackgroundService(PurposeOfConnection.AutomaticSync, null, context);  
                }
            }
        }

My problem is above function is called during server updates which is expected but it also gets called randomly for every 2 to 3 minutes (not sure about timings, its random) within the app without any push from server. Inside this function I am connecting with server to get latest data, because of this behavior its syncing with server without any updates. Currently I fixed this, by checking payload message to make sure that its from server.

I want to know whether this is normal behavior?

Sign In or Register to comment.