Run a background task every X times
2 answers
You can use the method Device.StartTimer(TimeSpan minutes)
to start a background task that will repeat itself after a specified amount of time. Here's some sample code:
var minutes = TimeSpan.FromMinutes (3);
Device.StartTimer (minutes, () => {
// call your method to check for notifications here
// Returning true means you want to repeat this timer
return true;
});
This is included with Xamarin Forms, so you don't need platform specific logic.
+8
source to share
I think the best you can do is this:
Unfortunately, the way the two platforms have evolved to handle background code is completely different. Thus, we cannot abstract the background function into the Xamarin.Forms library. Instead, we will continue to rely on native APIs to complete our common background task.
More information on this topic can be found here: https://robgibbens.com/backgrounding-with-xamarin-forms/
+1
source to share