xamarin / AndroidSupportComponents

Xamarin bindings for Android Support libraries - For AndroidX see https://github.com/xamarin/AndroidX
MIT License
146 stars 56 forks source link

Does Xamarin support WorkManager now? #152

Closed jom16antonio closed 5 years ago

jom16antonio commented 5 years ago

This is just a quick inquiry. How do I use WorkManager with Xamarin? Is this something being worked on?

VS bug #805952

moljac commented 5 years ago

Yes. I finished the bindings and am working on nuget package. I hope it will be released soon.

Redth commented 5 years ago

WorkManager is still in preview from Google. We are working on bindings for it in the meantime.

jom16antonio commented 5 years ago

Theres a rc01 (release candidate) hope we could test your bindings with that version.

chrisreps commented 5 years ago

Any update on WorkManager support, now that Google have pushed a stable release, identical to the release candidate, on the 5th of March?

Redth commented 5 years ago

https://www.nuget.org/packages/Xamarin.Android.Arch.Work.Runtime

Just published, should work for you now :)

sdobart commented 5 years ago

I added that NuGet package to my project, but I don't appear to have any access to the Xamarin.Android.Arch namespace?

Edit: Fixed. It helps if you target v28 SDK, heh :)

eli191 commented 5 years ago

@sdobart How did you do? I cannot find the Worker class, can you help please?

sdobart commented 5 years ago

@elisabeth-mitton You need to change your Android project's target SDK to version 28 (9.0 Pie), and then install the NuGet Package "Xamarin.Android.Arch.Work.Runtime".

vnwonah commented 5 years ago

I am targeting SDK 28 and have the nuget installed yet getting the type or namespace AndroidX could not be found. Any help please? @moljac

jalbertSyncroTech commented 5 years ago

Can anyone comment if the Xamarin WorkManager bindings support "ListenableWorker"?

I know it supports "Worker", but that requires that all of the work be done synchronously. In order to do any asynchronous work the worker needs to sub-class "ListenableWorker" directly.

The "ListenableWorker" is supposed to have an abstract "startWork()" function, but I'm not seeing it in the class definition from the "Xamarin.Android.Arch.Work.Runtime" NuGet package. https://developer.android.com/reference/androidx/work/ListenableWorker.html#startWork()

SteveFarmerJr commented 5 years ago

Can anyone comment if the Xamarin WorkManager bindings support "ListenableWorker"?

I know it supports "Worker", but that requires that all of the work be done synchronously. In order to do any asynchronous work the worker needs to sub-class "ListenableWorker" directly.

The "ListenableWorker" is supposed to have an abstract "startWork()" function, but I'm not seeing it in the class definition from the "Xamarin.Android.Arch.Work.Runtime" NuGet package. https://developer.android.com/reference/androidx/work/ListenableWorker.html#startWork()

I was under the impression that Xamarin WorkManager's "Worker" was asynchronous. https://devblogs.microsoft.com/xamarin/getting-started-workmanager/

jalbertSyncroTech commented 5 years ago

@SteveFarmerJr The doWork() entry point is called from a background thread, but the execution itself is synchronous - there's no way to eg. start some asynchronous operation, giving the doWork() thread back to the pool and then resume on a different background thread when the operation is complete.

It's not a show stopper, you can call .Wait() which blocks the doWork() thread, it just makes it more difficult to work with existing async/await or IObservable C# code.

sdobart commented 5 years ago

While I have not tested that it actually works, I can confirm the bindings do exist for ListenableWorker, and I am able to inherit from it.

toussam commented 5 years ago

@sdobart: Indeed, we can create a worker that will inherit from ListenableWorker, but @jalbertSyncroTech is correct, the startMethod is currently not available.

@moljac: Could you implement it? :)

moljac commented 5 years ago

@toussam Open a new issue please!

Could you implement it?

Maybe implememntation is not necessary. Maybe the method was not surfaced for some reason.

And mention me. I did part of the bindings.

toussam commented 5 years ago

Done! Thank you for your quick reply @moljac. ~

Wishing you a great weekend!

sirkris commented 4 years ago

I found this thread on Google, trying to figure out what the namespace was for the "Worker" class because the docs (https://devblogs.microsoft.com/xamarin/getting-started-workmanager/) make no mention of it. Turns out the namespace we're looking for is AndroidX.Work, in case anybody else came here looking for the same thing.

How is anybody supposed to know this if the documentation omits it? A simple "using" statement at the top of your code examples would really go a long way in these cases.