I would like to notify my main application (if it is still running) when the ScheduledAgent has finished its background task.
Is it actually possible? I couldn't figure out how I could reference my App or MainPage
For simply protecting shared data access between main app and background agent using Mutexes have a look at this question. Maybe this already gives you a hint in the right direction.
But if you want to react to events like "the background agent just finished" (in main app) or "the main app starts up" (in background agent) then you might be out of luck. There is no simple direct communication available, let alone direct data access. You could use Sockets or Raw Notifications.
A method based on polling and Mutexes is discussed in this question.
Related
Typically I can FindWindow() using the class name to find other instances to be able to send a message to another process (of the same app). However, if the application started from the task scheduler in the background, FindWindow() fails to find it (I presume EnumWindows() would too).
the question is: how do you get the handle to a Main Window that is running in the background?
It's something that would rarely be used and only for an instant So setting up shared data areas seems like overkill. A shared mutex already exists (if the owners handle could be used?).
It's just to send a message to it so it can log its status since you can't see anything when it's running in the background.
TIA!!
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
I have an app which build on Xcode objective-c, I have a code and I need that code to run even if the user press the home button.
Is it possible to do it?
Refer to the Background Execution chapter of the App Programming Guide for iOS.
There are three difference scenarios for background network requests:
The user initiates a simple request and expect the server to respond reasonably quickly, but want to make sure that if the user leaves the app before the request complete, that it really has a chance to finish gracefully in the background.
See the Executing Finite-Length Tasks section of the aforementioned guide for a discussion on how to request a little extra minutes after the user leaves the app, and that may be sufficient to finish the network request.
You are requesting large volumes of data (or uploading a lot of data), where it is anticipated to possibly require more than a few minutes to finish, especially on slow connection.
In this case, as Phillip Mills pointed out, you can use a background NSURLSession (as discussed in the Background Transfer Considerations section of the URL Loading System Programming Guide: Using NSURLSession guide.
You want to periodically make very quick calls to your web service to check to see if there is any new data, even if the user isn't using your app at the time.
In this case, you should look into "Background Fetch". See the Fetching Small Amounts of Content Opportunistically section of the App Programming Guide for iOS. You can't control precisely when it checks, but it is a way to initiate short network requests even when the app isn't currently running.
Note, if this opportunistic background fetch determines that there is a large volume of data to be downloaded, you can combine this pattern with the previous pattern (the background NSURLSession I discussed in point #2).
For more information on this, see the WWDC 2013 video, What's New with Multitasking.
I have an app which needs almost no user interaction, but requires Geofences. Can I run this entirely within a background service?
There will be an Activity when the service is first run. This Activity will start a service and register a BroadcastReceiver for BOOT_COMPLETED, so the service will start at boot. It's unlikely that this Activity will ever be run again.
The service will set an Alarm to go off periodically, which will cause an IntentService to download a list of locations from the network. This IntentService will then set up Geofences around those locations, and create PendingIntents which will fire when the locations are approached. In turn, those PendingIntents will cause another IntentService to take some action.
All this needs to happen in the background, with no user interaction apart from starting the Activity for the first time after installation. Hence, the Activity will not interact with LocationClient or any location services.
I've actually got this set up with proximityAlerts, but wish to move to the new Geofencing API for battery life reasons. However, I have heard that there can be a few problems with using LocationClient from within a service. Specifically, what I've heard (sorry, no references, just hearsay claims):
location client relies on ui availability for error handling
when called from background thread, LocationClient.connect() assumes that it is called from main ui thread (or other thread with event looper), so connection callback is never called, if we call this method from service running in background thread
When I've investigated, I can't see any reason why this would be the case, or why it would stop my doing what I want. I was hoping it would be almost a drop-in replacement for proximityAlerts...
Can anyone shed some light on things here?
The best thing would be to just try it out, right? Your strategy seems sound.
when called from background thread, LocationClient.connect() assumes that it is called from main ui thread (or other thread with event looper), so connection callback is never called, if we call this method from service running in background thread.
I know this to be not true. I have a Service that is started from an Activity, and the connection callback is called.
I dont know about proximity alerts; but I cant seem to find an API to list my GeoFences. I am worried that my database (sqlite) and the actual fences might get out of sync. That is a design flaw in my opinion.
The reason LocationClient needs UI, is that the device may not have Google Play Services installed. Google has deviced a cunning and complex mechanism that allows your app to prompt the user to download it. The whole thing is horrible and awful in my opinion. Its all "what-if what-if" programming.
(They rushed a lot of stuff out the door for google IO 2013. Not all of it are well documented, and some of it seems a bit "rough around the edges").
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.