Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xamarin.forms long running background work

I'm new to Xamarin platform. I'm developing an application for all three major platforms (WP,iOS,Android) using Xamarin.forms. How can I sync data with my server in the background -> I need something similar to Android Service. I want to sync the data even when the user goes to a different screen of the app. It would be great if I could continue syncing the data even when the user leaves the app.

Thank you

like image 820
malinjir Avatar asked Mar 15 '15 09:03

malinjir


People also ask

How do I run background tasks in Xamarin iOS?

If you want to run background tasks anywhere in you application as your app is in the foreground, you’ll need to use what is called “ Background-Safe Tasks “. Xamarin iOS provides us a means of easily registering our tasks to run in the background.

Is there a way to run asynchronous tasks in Xamarin forms?

Though C# gives us a way to run asynchronous tasks already, it might not be enough. You could also attempt to do multi-threading, but Android and iOS have built-in mechanisms to properly manage background tasks in Xamarin Forms. Workers are classes responsible for background tasks management in Android.

Is it possible to do multi-threading in Xamarin forms?

You could also attempt to do multi-threading, but Android and iOS have built-in mechanisms to properly manage background tasks in Xamarin Forms. Workers are classes responsible for background tasks management in Android.

How do I run a background task in Android?

To run a background task in Android, you simply use a Service. Android generally classifies tasks as either Long Running Tasks or Periodic Tasks. Either of these, is reasonable grounds to create a Service.


2 Answers

This is the only solution i have found http://arteksoftware.com/backgrounding-with-xamarin-forms/

in a few words: You can't abstract background tasks in Xamarin.Forms because iOS, Android and WP works in a different way. You have to use MessagingCenter to send and receive data from specific implementations in each platform

like image 85
MatPag Avatar answered Sep 20 '22 11:09

MatPag


Have look to this article: http://developer.xamarin.com/guides/ios/application_fundamentals/backgrounding/part_3_ios_backgrounding_techniques/ios_backgrounding_with_tasks/

You could provably be interested in the Transfer Background tasks.

Regards

like image 28
Ramón Esteban Avatar answered Sep 18 '22 11:09

Ramón Esteban