locked
How to add background service in Xamarin forms RRS feed

  • Question

  • User365120 posted

    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.

    Wednesday, January 31, 2018 12:45 PM

Answers

  • User180523 posted

    I can't create background service in (PCL) That's correct. Because each platform has their own way and rules for background services. You have to make services for each platform.

    I don't want to be that guy that says "Google it" - but there are a number of tutorials directly from Xamarin that explain backgrounding. Have you looked? Getting your information directly from Xamarin is always the first place to start.

    https://developer.xamarin.com/guides/ios/application_fundamentals/backgrounding/ https://www.youtube.com/watch?v=Z1YzyreS4-o https://www.google.com/search?q=xamarin+university+background+services&ie=utf-8&oe=utf-8&client=firefox-b-1

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Wednesday, January 31, 2018 12:48 PM

All replies

  • User180523 posted

    I can't create background service in (PCL) That's correct. Because each platform has their own way and rules for background services. You have to make services for each platform.

    I don't want to be that guy that says "Google it" - but there are a number of tutorials directly from Xamarin that explain backgrounding. Have you looked? Getting your information directly from Xamarin is always the first place to start.

    https://developer.xamarin.com/guides/ios/application_fundamentals/backgrounding/ https://www.youtube.com/watch?v=Z1YzyreS4-o https://www.google.com/search?q=xamarin+university+background+services&ie=utf-8&oe=utf-8&client=firefox-b-1

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Wednesday, January 31, 2018 12:48 PM
  • User365120 posted

    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

    Wednesday, January 31, 2018 1:10 PM
  • User180523 posted

    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.

    Wednesday, January 31, 2018 1:21 PM
  • User380513 posted

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

    Saturday, February 9, 2019 9:53 AM
  • User198446 posted

    @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

    Saturday, February 9, 2019 10:31 PM
  • User380513 posted

    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

    Sunday, February 10, 2019 10:25 AM
  • User380513 posted

    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

    Monday, February 11, 2019 1:12 AM
  • User292509 posted

    Hi ClintStLaurent and other developers,

    I tried the sample developed by Rob Gibbens

    https://robgibbens.com/backgrounding-with-xamarin-forms/

    On my iPhone 6+ with iOS 12, the sample works well with debug model. But when start the app on my iPhone, start LongRunning task and lock iPhone or press iPhone's home button, the background task will be cancelled automatically after 3 minutes even though check Background model, Background fetch, Background processing on Info.plist page. Do you have any suggestion to solve the issue?

    @ClintStLaurent said:

    I can't create background service in (PCL) That's correct. Because each platform has their own way and rules for background services. You have to make services for each platform.

    I don't want to be that guy that says "Google it" - but there are a number of tutorials directly from Xamarin that explain backgrounding. Have you looked? Getting your information directly from Xamarin is always the first place to start.

    https://developer.xamarin.com/guides/ios/application_fundamentals/backgrounding/ https://www.youtube.com/watch?v=Z1YzyreS4-o https://www.google.com/search?q=xamarin+university+background+services&ie=utf-8&oe=utf-8&client=firefox-b-1

    Sunday, March 15, 2020 1:10 AM
  • User393523 posted

    Have any one find the solution? I am experiencing the same. When app heads to background, app pauses the execution of thread/task and when app comes to foreground it resumes the execution of thread/task. I want to execute the peace of code even app is in minimized mode or phone is locked. Anyone has idea for it?

    Thursday, March 26, 2020 5:24 AM
  • User393523 posted

    I am facing same issue. Have you find the solution ?

    Thursday, March 26, 2020 5:27 AM