Maui Android support for WorkManager #4065
-
Hello there, |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 3 replies
-
Instead of Xamarin.Android.Arch.Work.Runtime, try using Xamarin.AndroidX.Work.Runtime. See also http://damien.dennehy.me/using-workmanager-and-listenableworker-in-xamarin-android/. |
Beta Was this translation helpful? Give feedback.
-
I managed to make it work with public void SyncData()
{
using var builder = new Constraints.Builder();
builder.SetRequiredNetworkType(NetworkType.Connected);
var workConstraints = builder.Build();
var workerRequest = new OneTimeWorkRequest.Builder(typeof(DataSyncWorker))
.SetConstraints(workConstraints)
.AddTag(DataSyncWorker.TAG)
.Build();
WorkManager.GetInstance(Microsoft.Maui.ApplicationModel.Platform.AppContext)
.EnqueueUniqueWork(DataSyncWorker.TAG, ExistingWorkPolicy.Keep, workerRequest);
} and the worker class that implements either |
Beta Was this translation helpful? Give feedback.
-
I am interesting to run a background task, and it seems that the Worker could be a solution for me. But I am new and I am a bit lose by the moment. In the asnwered solution, the SyncData() method, where is implemented? In a class insde Platforms\Android folder or in the MAUI folder? I mean if it is an especific class of Android or a generic class. could it be possible you could share the code that works for you? Thanks so much. |
Beta Was this translation helpful? Give feedback.
-
is there a full example for this? |
Beta Was this translation helpful? Give feedback.
I managed to make it work with
<PackageReference Include="Xamarin.AndroidX.Work.Runtime" Version="2.7.1.5" />
Here is a sample code: