background process and UI interaction - windows-phone-7

I am working on an application that is receiving XMPP notifications using the Matrix SDK. As well I am using async web service calls to receive an initial set of data from the server.
Now, I am aware that with Mango I can close the app or move it to the background and have a background task that is able to be run every 30 mins (or so) for 15sec max which obviosuly means the XMPP push isn't going to work in this scenario. Is there any way to get background apps to execute more frequently than this?
Failing that for the syncing process all I can do is every 30 mins use a web service call to get any updates and store into Isolated storage for my app to pick up when it's next run. But I believe I cannot use any UI from a background task so cannot tell the user of updates?
So, if I get an important message can I somehow override the slowness here and force my app to run and inform the user visibly that something has happened and he needs to look at it? Is this where push notifications come in?

You can use the ShellTile API to update the application's tile on the Start screen, or use the ShellToast API to show a toast to the user. Both of these can be configured to launch into a specific part of your application (deep-linking) when tapped.
If you need a constant monitoring/update/notification system for your application when it's not running, then using push notifications is probably the more appropriate approach.

Related

Confusion between all backgrounding options (and their evolution in time) with Xamarin.Forms Android

I've tested various backgrounding options (xamarin samples, xamarin blog articles, various sources) but I'd like some clarification on the pro/cons of each one, and if some are deprecated/obsolete.
My case is an app (wifi, on client premises) that should periodically poll a server for new data, or push collected data to the server as soon as it has connection (it should continue to collect data if no connection is available, but push to the server as soon as it has connection).
I want this sync to be in the background for the user, who in the meantime can continue to work.
I would like the push (if data is present) to be done each 1 or 2 minutes, so I can just create a task in the background job with an infinite while that checks every 1/2 minutes.
I made some basic samples to test:
1) using a LongRunningTaskService : Service
2) using Firebase.JobDispatcher
3) using WorkManager (but scheduled jobs can't be less than 15 minutes)
4) looking at Shiny, but currently having trouble integrating with Prism (but I guess I'll make it work)(but don't understand if it is a wrapper of what exactly?)
Which solution do you think is appropriate for my use case?
With all the 4 solutions, data should be pushed when the app is in foreground or background (right?)
In case I need to push data only when the app is in the foreground, would it be wrong to start my Task in App class?
UPDATE
Tried this in the OnInitialized() of the App.cs:
Task.Factory.StartNew(async () =>
{
while (true)
{
await BackgroundTasks.TestPushDataRepeat();
await Task.Delay(60000);
}
}
, TaskCreationOptions.LongRunning);
It works every minute when the app is in foreground (and doesn't block the UI), but unexpectedly works also when the app is backgrounded (that is a not needed plus, for my case). Not being a service, I thought it should have freezed, why is that?
I'm trying to better understand/separate how the TPL works with Xamarin on Android, and how Android backgrounding (services/workers etc) works, to see if this solution has drawbacks.
On Android, you cannot run a background task/job/worker every 30 seconds. Such behavior can have a negative impact on the battery and can only be achieved with a Foreground Service that requires a notification visible to the user.
The limit you see for WorkManager about the 15 minutes minimum interval is an OS constraint, not a library constraint. You have the same limit if you use JobScheduler. Also a Worker (or Job if you're using JobScheduler) can run only for 10 minutes.
So, you need to have a Foreground Service. You can still use WorkManager and its advanced features in this case, but you need to use WorkManager 2.3+ and "promote" your worker to a Foreground Service. WorkManager's documentation covers this use case.
This for native Android (Java/Kotlin). I don't know how the latest Xamarin binding cover this use case.

NativeScript geolocation in the background

My use case is the following - being able to periodically send updates to a web service with the current location of the device on which the {NS} app is running. This should happen even if the app is "minimized".
I saw that workers have been added to the framework, but as I understand it, the app is supposed to be active(not minimized) for the worker to execute.
Is there a way to accomplish this?
Cheers
You need to use background-services for this purpose.
NativeScriptBackgroundServices

Windows Universal Platform: Background task to check email

I want to develop an app that has a background task that checks email servers (POP, IMAP, etc) for new email.
From what I can tell of background task, it is only allowed to run for a short time, and can be started only every 15 minutes if it is a timertrigger.
Since I want this app to run on all Windows devices, what is that proper approach to having a background task that can do this? It doesn't seem possible at this point.
But since Windows devices are able to check email in the background, there must be a way. Does anyone have any insights?
What you wish to achieve is a near real time notification of user about a mail he received . You are right that Windows doesn't allow a background task to run at intervals lesser than 15 minutes . What you are looking for is Windows Push Notification Service which can be used to send notifications from your own cloud service onto the device
It is not possible to use a background task working all time to get in real time the new emails in your case.
You must implement another approach may be using your own backend to implement push notifications to send a new notification when a new email is received.
If your provider has an API you can use it.

Appcelerator Background Job

We are developing an app(iOS) in appcelerator which has a sync contact feature in it. This calls an API which syncs contacts with server. I want this to run in background of the app. It should not make the user stop on a screen. Can anyone help me on this?
If you use the iOS background it's only when the app goes to the background and has limitation set by the OS - so if, for example it takes too long to process, or if the OS needs memory - it will shut it down.
I'm guessing (correct me if I'm wrong) that you want to do the sync while the app is running, yet not compromise the user experience by freezing the app?
First of, know the the request to the server is made async - only processing the response is made on the js thread - so to make better use of your single thread I suggest you view the following presentation: http://www.slideshare.net/ronaldtreur/titanium-making-the-most-of-your-single-thread
If you truly want a background thread to do the job, currently you would have to write your own native module to do that.
Also, this is something to look forward to in future versions: https://github.com/appcelerator/cspec-titanium-multithreading
You can use the background service for that.
But be aware, that this services will stop after a few minutes

Running Windows phone 7 app in background

I want a part(Service) in my windows phone app to run periodically.Actually its a server request , which should be made periodically and show any changes to user as notification
You should use the PeriodicTask which runs every 30 minutes in the background unless the user has not forbidden that. Notify the user about changes with a ShellToast or think about Push Notifications.
Important: Please keep in mind, that you can never rely on background tasks in Windows Phone. There are many reasons why such a task will not run. So do not outsource necessary or important work to it.

Resources