Skip to content
This repository has been archived by the owner on May 15, 2024. It is now read-only.

Please support Background task! #409

Closed
nguyenthanhliemfc opened this issue Jul 25, 2018 · 23 comments
Closed

Please support Background task! #409

nguyenthanhliemfc opened this issue Jul 25, 2018 · 23 comments
Labels
feature-request A request for a new feature. needs-more-discussion This needs more discussion or info before discussing it as a proposal. needs-specifications Accepted feature/enhancement and needs specification. proposal Proposed feature or enhancement.

Comments

@nguyenthanhliemfc
Copy link

nguyenthanhliemfc commented Jul 25, 2018

Thank you for Essentials. It's help me a lot in development app
It will be nice if support Background Task!
Thank you!

VS bug #735660

@jamesmontemagno
Copy link
Collaborator

Can you describe more as to what you mean here.

@nguyenthanhliemfc
Copy link
Author

Sorry for my bad English.
I mean please support easy way to help developer implement Background Task in app. Thank!

@jamesmontemagno
Copy link
Collaborator

Do you have an example of the APIs on each platform you are looking to have abstracted?

@nguyenthanhliemfc
Copy link
Author

Example I want to send a GET method to get news every 15 min without open app!

@cfl777
Copy link

cfl777 commented Jul 27, 2018

Andriod new component for this is the Android WorkManager api - doesn't seem like Xamarin supports this yet. But it would be great to have a scheduler for both platforms supported on Essentials

@Mrnikbobjeff
Copy link
Contributor

Mrnikbobjeff commented Jul 28, 2018

I strongly support this proposal. We needed this for several apps and always rolled our own implementation, which always added overhead until you got everything right. Scheduling actions is very platform specific, and there is a huge potential for miususe. I.E. iOS, if you take a look at the docs you can see that for apps that need to update from time to time as i guess @nguyenthanhliemfc has to do you can see that it states

Enabling this mode is not a guarantee that the system will give your app any time to perform background fetches.
The only apps that can permanently run in the background on ios are voip, location and audio.

Android is a lot more liberal with its Job scheduler (docs). It can specify a deadline, indicate that the job is to be persisted across reboots etc. It is available from Android 5.0 onward, for 4.4 we would have to look at the Alarm Service. This is also more permissive than iOS, thus we would still be limited by iOS.

Finally, UWP is also mightier that iOS in that regard (docs). You have certain restrictions such as the minimum interval allowed between internally triggered background events is 15 minutes, and that your app only has 30 seconds to process your tasks.

In conclusion, the only common api I would feel comfortable to expose without overpromising is something like this:

public static class Scheduler
{
public static void ScheduleJob(JobDelegate callback, JobOptions interval);
}
where JobOptions is a wrapper class to manage the android and uwp specific parts as well as an ID tag to differntiate betwenn jobs. The Jobdelegate is responsible for deciding whether the task was a success and whether it needs to be rescheduled. Then document that iOS is way more restrictive.
This was exactly what we needed, invalidate and refresh a local cache periodically. We did not care when or if it happened, only that if it happened it was when the app was not in foreground but had been launched somewhat recently. This fits the cross platform api service we would expose.

@jamesmontemagno jamesmontemagno added proposal Proposed feature or enhancement. needs-more-discussion This needs more discussion or info before discussing it as a proposal. labels Jul 29, 2018
@nguyenthanhliemfc
Copy link
Author

nguyenthanhliemfc commented Jul 30, 2018

In my company have Server and Client app. My boss assigns the job to the employee on Server
Case 1: Client need get new data from Server every 15 min if have new records Client app will show local notification about new records.
Case 2: Client app will send current location of Staffs to server every 15 min ( Maybe every 5 min or differrent time).
Client app run on tablet Windows (some Windows Phone), Android and iPhone

@pingzing
Copy link

pingzing commented Aug 5, 2018

I'll add a +1 and a use case to this.

One example that comes up a lot is long-running tasks. For example, we had a phonebook app that, because of Reasons(tm) needed to do a large fetch of the latest phonebook on startup. Being able to reliably do this in the background would have been excellent. As it was, we had to do it in the foreground, and hope we were lucky enough that the user didn't switch away during the download.

So perhaps there are two cases here:

  • Recurring, background tasks for basic upkeep
  • Long-running tasks that should persist, and notify when complete.

@nrb1238
Copy link

nrb1238 commented Sep 25, 2018

+1 Vote

@concedev
Copy link

+1

@mattleibow
Copy link
Contributor

I saw this: https://github.com/aritchie/jobs

@Redth Redth added needs-specifications Accepted feature/enhancement and needs specification. azdo-sync labels Nov 26, 2018
This was referenced Nov 26, 2018
@xamarin-release-manager xamarin-release-manager added the feature-request A request for a new feature. label Nov 28, 2018
@KSemenenko
Copy link

This is a good idea, I just need this functionality.

In my application, I need to periodically do synchronization with the server, so as in the project that showed @mattleibow, it would be nice to do Backround Task that are inherited from the interface. We can place or delete them from the container of active tasks, and thus get control over the tasks.

for example, when an application goes into sleep mode or is terminated, we can put the necessary task in the container. and when the application returns to its working state, take it back.

@KSemenenko
Copy link

One moment is Apple's permission. They have a list of allowed actions in Background mode. We need to make sure that Apple will allow the publication of the application.
I know examples when developers indicate permission to play music in the Background mode, and download the data themselves. as a result, Apple does not allow the publication of such applications.

@mzhukovs
Copy link

Relevant link for anyone looking for more info on this

@nguyenthanhliemfc
Copy link
Author

nguyenthanhliemfc commented Mar 6, 2019

Thank you @mzhukovs It's great topic. I still need a support from Xamarin Team release a simple way to implement some type of background task!
Beside this link is another way to implement background task LINK

@AmirImam
Copy link

+1

@jamesmontemagno
Copy link
Collaborator

While this is in our backlog for a feature request I would recommend checking out the excellent Shiny project: https://github.com/shinyorg/shiny

@github-mit-programming
Copy link

github-mit-programming commented Jun 21, 2020

@jamesmontemagno ...background task is all ok. ...HOW TO USE XAMARIN ESSENTIALS IN FOREGROUND OR BACKGROUND SERVICE IN ANDROID WHICH NEEDS TO RUN EVEN HEN APP UI CLOSES? How can we init the Xamarin.Essentials.Platform.Init? OR is there some workaround? Android background or foreground service doesn't have needed params to initialize that xamarin essentials dll. THIS BLOCKS ALL FEATURES OF XAMARIN ESSENTIALS TO BE USED IN A BACKGROUND OR FOREGROUND SERVICE. NOTE: service is backbone architecture of worthy android apps, rest is all for amateurs.

TO BE SPECIFIC:
This code cannot be called in Service class as these params are not available in a foreground long-running service which doesn't close after app closes.
// Initialize xamarin essentials
Xamarin.Essentials.Platform.Init(this, savedInstanceState);

@nguyenthanhliemfc
Copy link
Author

@jamesmontemagno ...background task is all ok. ...HOW TO USE XAMARIN ESSENTIALS IN FOREGROUND OR BACKGROUND SERVICE IN ANDROID WHICH NEEDS TO RUN EVEN HEN APP UI CLOSES? How can we init the Xamarin.Essentials.Platform.Init? OR is there some workaround? Android background or foreground service doesn't have needed params to initialize that xamarin essentials dll. THIS BLOCKS ALL FEATURES OF XAMARIN ESSENTIALS TO BE USED IN A BACKGROUND OR FOREGROUND SERVICE. NOTE: service is backbone architecture of worthy android apps, rest is all for amateurs.

TO BE SPECIFIC:
This code cannot be called in Service class as these params are not available in a foreground long-running service which doesn't close after app closes.
// Initialize xamarin essentials
Xamarin.Essentials.Platform.Init(this, savedInstanceState);

Do you have try MessageCenter to call it from Service class?

knocte pushed a commit to aarani/DotNetEssentials that referenced this issue Nov 4, 2020
Also bump from 1.5.9999 to 1.5.99999 to distinguish
if it includes background task support.

Fixes xamarin#409
knocte pushed a commit to nblockchain/DotNetEssentials that referenced this issue Nov 4, 2020
Also bump from 1.5.9999 to 1.5.99999 to distinguish
if it includes background task support.

Fixes xamarin#409
knocte pushed a commit to nblockchain/DotNetEssentials that referenced this issue Nov 11, 2020
Also bump from 1.5.9999 to 1.5.99999 to distinguish
if it includes background task support.

Fixes xamarin#409
knocte pushed a commit to nblockchain/DotNetEssentials that referenced this issue Nov 12, 2020
Also bump from 1.5.9999 to 1.5.99999 to distinguish
if it includes background task support.

Fixes xamarin#409
knocte pushed a commit to nblockchain/DotNetEssentials that referenced this issue Nov 12, 2020
Also bump from 1.5.9999 to 1.5.99999 to distinguish
if it includes background task support.

Fixes xamarin#409
@elielson-anjos
Copy link

Did it make it through? I need to periodically send information to my server all day long from an android device.

@linda-dge
Copy link

I need this functionality as well.

knocte pushed a commit to knocte/Essentials that referenced this issue Feb 3, 2021
Also bump from 1.5.9999 to 1.5.99999 to distinguish
if it includes background task support.

Fixes xamarin#409
knocte pushed a commit to knocte/Essentials that referenced this issue Feb 3, 2021
@knocte knocte mentioned this issue Feb 3, 2021
5 tasks
@knocte
Copy link
Contributor

knocte commented Feb 3, 2021

Hey @Rothanan, @linda-dge (and others), my team and I have proposed a PR: #1674 . Can you help us add Samples, documentation and test it? Thanks!

@jfversluis
Copy link
Member

Thanks everyone for the input here! We won't be doing this for Xamarin.Essentials anymore. I highly recommend you look at Shiny a library that does this very well.

Background tasks have a lot of considerations. We are definitely willing to consider this for .NET MAUI but I would like to ask you that if you open an issue or discussion to add a lot of detail on how you would like to use it. Without it, it will be pretty hard to make a plan for it. Again, thanks and hopefully we can get this in .NET MAUI at some point in time!

knocte pushed a commit to nblockchain/DotNetEssentials that referenced this issue Jul 26, 2022
knocte pushed a commit to nblockchain/DotNetEssentials that referenced this issue Jul 26, 2022
knocte pushed a commit to nblockchain/DotNetEssentials that referenced this issue Jul 27, 2022
Fixes xamarin#409

Upstream PR: xamarin#1674

(Removed .netstandard1.0 target framework because it doesn't support
OS checks.)

Co-authored-by: Taras <mail@webwarrior.ws>
knocte pushed a commit to nblockchain/DotNetEssentials that referenced this issue Aug 14, 2022
Fixes xamarin#409

Upstream PR: xamarin#1674

(Removed .netstandard1.0 target framework because it doesn't support
OS checks.)

Co-authored-by: Taras <mail@webwarrior.ws>
knocte pushed a commit to nblockchain/DotNetEssentials that referenced this issue Aug 23, 2022
Fixes xamarin#409

Upstream PR: xamarin#1674

(Removed .netstandard1.0 target framework because it doesn't support
OS checks.)

Co-authored-by: Taras <mail@webwarrior.ws>
knocte pushed a commit to nblockchain/DotNetEssentials that referenced this issue Aug 23, 2022
Fixes xamarin#409

Upstream PR: xamarin#1674

(Removed .netstandard1.0 target framework because it doesn't support
OS checks.)

Co-authored-by: Taras <mail@webwarrior.ws>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature-request A request for a new feature. needs-more-discussion This needs more discussion or info before discussing it as a proposal. needs-specifications Accepted feature/enhancement and needs specification. proposal Proposed feature or enhancement.
Projects
None yet
Development

No branches or pull requests