Forum Xamarin Xamarin.Android

Return results from Background service

Hi All,
Am newbie to xamarin.android currently i have a requirement where i have to keep receving messages from a third party server via wss protocol. So, am running a background service where i have scheduled a job for every twelve seconds, am connecting to third party server and receiving messages via wss protocol. But, am unable to process that message within application. The method does not return if i try to return a string message. I have tried registering an explicit broadcast receiver to process the message. But, its unreliable sometimes it overrides onReceive where as most of the times it does not even override. Please suggest some solution. Following is the code

Action myAction = async () =>
{
await connectToServer.ReadNotificationServer();

            };

handler.PostDelayed(myAction, 12000);
Am calling this method within OnStartCommand, ReadNotification server method reads the message from WSS protocol. But, not able to register receiver. I can provide further elaboration.

Best Answer

Answers

  • Nivedita_PuneetNivedita_Puneet Member ✭✭

    Thanks a lot, The Job scheduler gives us desired results. But, Issue am facing is I need to register a dynamic broadcast receiver and need to receive results after finishing job. It never calls onReceive of Broadcast receiver via an explicit intent. I faced the same when I was using Intent service and Handler.

  • JarvanJarvan Member, Xamarin Team Xamurai

    Please check whether the Enabled property of the BroadcastReceiver has been set to true and the action of IntentFilter is correct.

    Tutorial:
    https://docs.microsoft.com/en-us/xamarin/android/app-fundamentals/broadcast-receivers

Sign In or Register to comment.