Backgrounding with Xamarin.Forms
Asked Answered
A

2

5

I am currently planning a Xamarin.Forms app and while doing so i came across a point which seems to have no answer.
The app will have to work with a WCF Service to get its data and also to tell the service to do certain tasks. While the application is active, doing so is easy. But there is something the App has to do. Call the Service every x Minutes to refresh data and create notifications for the user in some cases. I've read something about backgrounding in iOS or Services in Android, but there seems to be no way for a Xamarin.Forms aplication to have a common way of doing background work. So, how can I access the WCF service, and process the data, while the app is inactive in Xamarin.Forms?

Anglesey answered 16/10, 2015 at 8:19 Comment(3)
arteksoftware.com/backgrounding-with-xamarin-formsTrap
So... as long as the app is running in the background but not terminated, a Task will run. But what if the app is terminated? Will a such a task also be terminated? How do Apps like WhatsApp keep me synced even if the app is closed?Anglesey
Correct, as long as the app is not terminated, once terminated, your tasks are of course terminated. Apps like WhatsApp register to use iOS Push Notifications, Android/Google has a similar Notification queue. You need to read the platform specific droid service and iOS Background tasks as they are really different : developer.apple.com/library/ios/documentation/iPhone/Conceptual/… developer.android.com/reference/android/app/Service.htmlTrap
S
5

This is the only solution I have found: https://robgibbens.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.

A similar thread (I copied my answer from here): Xamarin.forms long running background work

Staton answered 18/12, 2015 at 8:52 Comment(1)
First link no longer valid.Afflatus
F
4

You do it in the same way wih Xamarin as you would do it in an Objective-C or Java app. You use the same API to register a background service.

There are also documents about it for iOS and for Android.

Xamarin uses the same native API on each system like any other native app does. So everything you want to do with Xamarin can be done the same way as you would use the vendors' original toolings. The only difference is the programming language.

Xamarin.Forms is completely irrelevant here. It is an abstraction layer for the native UI frameworks that enable developers to define the user interface once and run a truly native UI on Android, iOS, Windows Phone and Windows Store apps. It has nothing to do with backgrounding here.

Fierce answered 16/10, 2015 at 8:47 Comment(2)
Just thought that there may be an abstraction Layer for that. I'm not familiar with backgrounding at all, didn't need that so far.Anglesey
You'll find a few exceptions but currently Xamarin.Forms is on UI abstraction and it's complicated enough to keep them busy. But thanks to dependency services it's easy to create an abstraction layer on any platform-specific APIs as long as they are rather compatible with each other. I haven't yet given a thought to backgrounding and how do create a common dependency service but I do know from experience that iOS and Android backgrounding concepts are VERY different. So it could be hard to create a good abstraction layer.Catachresis

© 2022 - 2024 — McMap. All rights reserved.