How to add background service in Xamarin forms

I am new developer in xamarin,
That's why i faced some problem.
I can't create background service in (PCL) Android, iOS and also UWP.

Anybody help me to give example code or station.

Best Answer

Answers

  • SmfKarimSmfKarim Member ✭✭

    I want to know about,
    when start my app this time run a service in background like location trace / data update in my web server etc and when closs my app stop backgrount service.
    how to do it (PCL) Android, iOS and also UWP

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    how to do it (PCL) Android, iOS and also UWP

    You don't. Aren't you reading my earlier posts - or the Xamarin tutorials/links/videos I posted on background services? Just because you want it doesn't make it possible. Background services have to be made on a per-platform basis. Period. Accept that.

    If you want to do it within your app on its own thread - you could do that. Just like any other thread you make. But it won't be a service - its just a thread performing a recurring action.

    Since this is only supposed to happen while your app is running, you could just react to the location changed event of the Location plugin, and then upload the data to your server. It doesn't have to be a service. Its just responding to an event, no different than any other event like handling a button.click event or a listview.itemselectionchanged event.

  • wondererwonderer Member ✭✭

    Hi, this is one year old, seem to knowledgeable about this, aware of any xamarin forms packages that wrap this so far?

  • AndreiMisiukevich_AndreiMisiukevich_ USMember ✭✭✭✭✭

    @wonderer said:
    Hi, this is one year old, seem to knowledgeable about this, aware of any xamarin forms packages that wrap this so far?

    Sure, https://github.com/winstongubantes/MatchaBackgroundService

  • wondererwonderer Member ✭✭

    Thanx Andrei, google did not bring up this one, I assumed it should be fairly simple.

    This means I call the dependencies in the plattforms, and from there I can than call more class in the shared code, which gives me the ability to run services on many platforms through the shared code

  • wondererwonderer Member ✭✭
    Hi,

    This calls the code every x seconds, just for clarification, I need to run the service, when I have screen lock or app in background,

    This sample calls thread every x secs, can I still use it for my case somehow adapted

    Thanx

    Walter
Sign In or Register to comment.