When adding a background task in WinRT with a trigger of SystemTriggerType.InternetAvailable
if the internet is available when the task is registered will if execute right then? or will the task wait for the internet to not be available and then available again to execute?
Or can I force execution of that background task when my app is active?
A backround task with SystemTriggerType.InternetAvailable will only start when Internet becomes available. If it's already available when the task is registered, it won't trigger.
If you need to execute that code even if internet is available all the time, the best thing would be to create another background task with TimeTrigger and SystemConditionType.InternetAvailable. You are allowed to set it to the minimum interval of 15 minutes.
If you also need to be able to execute the same code from your app immediately, then put the relevant code in a separate library and call it both from the background tasks and the application code.
Related
This is a Windows Phone 8.1 app. I want to be able to trigger a task to execute at a specific time. My main concerns are accuracy, resource and user experience.
I have tried a TimeTrigger with an IBackgroundTask but found that, aside from the minimum 15 minutes constraint, the execution time is far from accurate - sometime the task triggers 8 minutes later, some times 20 so no use for a scheduled trigger.
I have looked at toast but I need the task to run without user input and, as far as I can see, the toast notifications have no capability to trigger code execution without the user interacting.
I have looked at the alarm clock approach but, firstly it uses toast notifications and, secondly, I understand you can only have one alarm app that the user must declare so that's a bit intrusive.
I have looked at using a Task.Delay approach using async and await to avoid blocking the UI thread but this is hardly a background-centric approach.
Has anyone managed to find a way to create resource-friendly, scheduled background tasks (i.e. an alarm and sleep function) for Windows Phone 8.1?
I'm using the AS3 Timer class to sync data between a Flex Mobile app and a server ideally every 30 mins then send a local (distriqt) Notification to the user when action is required.
However, when the device goes into sleep / hibernate mode it seems to slow down, even stop the Timer. I've tried using a lower interval (5mins) but it still only works intermittently.
This is very hard to test as the behavior is different in debug / run modes.
Any suggestions?
Thanks.
Sounds like you might need to change your approach here. Background operation of applications is very different from the foreground.
Your application will run for a little while (depending on the current device memory load among other things) and will then enter a suspended mode, mainly to preserve the application's memory state.
There are some background mode exceptions to this, such as audio playback and location updates, however if you aren't performing these then Apple will most likely reject your application as part of the review process.
You can also investigate the executeInBackground flag on the NativeApplication. This allows a long running task to execute in the background, however this does not guarantee that the application would run in the background continuously.
You can read more here: http://blogs.adobe.com/airodynamics/2012/05/04/air-ios-background-behavior/
UIBackgroundModes: https://developer.apple.com/library/ios/documentation/General/Reference/InfoPlistKeyReference/Articles/iPhoneOSKeys.html#//apple_ref/doc/uid/TP40009252-SW22
When a user first opens my app, I need to download and install some content from a server before they can begin using the app. The problem is that this takes around 5 minutes on wifi, during which time the app goes into the background and the download is suspended.
Is there any way to either:
Prevent an windows app from entering the background while I perform my download
or continue peforming the task in the background (i.e. perform the task irrespective of whether the app is in the foreground or background)
Also, I don't want to use the BackgroundDownloadManager
Thanks
When the app is being suspended, all processes are stopped and and background task cancelled. Your last chance to do something is Suspending event - see more at MSDN.
In your case, when you need to download big file in the background - the mentioned BackgroundDownloader would be the best option - it's designed for such tasks. In other cases you will have to convince user to leave the app in the foreground (a message?), also take care about lockscreen (see DisplayRequest class).
I'm not also sure but maybe you will be able to use BackgroundTask (separate process), triggered with MaintanceTrigger - but then user will be able to download the file only in specific circumstances and probably not right away.
I'm encountering a strange issue when a background task is executing then the user launches the foreground application. If the user launches the app while the background task is executing, the background task is terminated. Is this normal or expected behavior?
The background task begins and ends with success in the following scenarios:
The foreground app is currently running
The foreground app is not running
I've read the following post as it seems to be the exact issue I'm experiencing. However, the responses don't apply since I already have a reference to the background task project. This is required for a background task to even work and be registered.
Update 3/16/2014
I've discovered that this may be more edge case than I originally anticipated. In the following scenario the application is launched successfully and the background task is not terminated.
Fresh boot of machine
Background task is manually triggered (currently triggered by InternetAvailable)
Launch Application
What I've discovered is that when the following steps are run the background task will terminate upon application launch
Launch application
Manually close application
Trigger background task
Launch application (application is displayed immediately as if it was suspended. Oddly enough when I run the application after closing it every other time the splash screen is always displayed. In this scenario when the background task is triggered the application seems to be in a suspended state)
Manually close application
Launch application
Again, I understand this is a very odd set of steps to reproduce this issue but if anybody is running across this or it is an expected behavior please let me know.
Thanks in advance.
I am trying to provide my users with the option to have my application launch automatically and complete a task at a certain time every week.
I can make my application launch at log in using NativeApplication.nativeApplication.startAtLogin=true but I then want to detect if the time is the time they selected and if it isn't then run the application in the background until the time does match or the user shuts down their computer.
Does anyone know of a way to do this? On Adobe's webpage comparing Flex web apps and desktop apps it implied to me that applications could be run in the background but I'm struggling to find anything.
You can close the initial native window without killing the process
NativeApplication.nativeApplication.autoExit = false;
NativeWindow(this.stage.nativeWindow).close();
OR
You can close the initial native window and create a new window that acts as a desktop widget without appearing in the taskbar with either the UTILITY or LIGHTWEIGHT window type.
http://help.adobe.com/en_US/air/reference/html/flash/display/NativeWindowInitOptions.html#type
Either you keep the process running which times when the next 'job' should be ran, or you can set a system cron job (or something similar) which is specific to the OS. You'll want to use the NativeWindow option of 'LIGHTWEIGHT' so that your application doesn't show up to the user.
Personally, for these kinds of processes, I don't even try to use Air since it isn't really made for this kind of stuff. It's meant to be used for UI based apps and not process based. Use Java or C# instead.