Run script after windows store app has been installed - windows-8

Is there any way to run some activity after a Windows Store app has been installed?
I'd like to get some data from a webservice (data is rarely changes), but I would not like to make the query on the first start, because it might take some time, and I don't want to ruin the user experience.
Thanks!

You can have it run on a separate background thread while concurrently running the main thread. You can allocate limited resources to this separate background thread, then have it subside on it's own.
You can do an async operation as well from your app, see link from MSDN:
http://msdn.microsoft.com/en-us/library/windows/apps/br230301.aspx#AsyncOps

My codeSHOW app loads data asynchronously when it first starts, and stores the async promise as an app level variable so anything else in the app can await it. It's not exactly what you're looking for, but if it helps, it's available at http://codeshow.codeplex.com.

Related

Background task for reading accelerometer data

I have a React Native application and I am reading accelerometer data each 20ms using the react-native-sensor-manager package.
I start the listener and log it into Reactotron each time it reads data, each 20ms
SensorManager.startAccelerometer(20)
DeviceEventEmitter.addListener('Accelerometer', function (data) {
console.tron.warn(data)
})
It works well if I leave the application in foreground, and even in background, but if I lock the phone it stops reading data. It also stops if I kill the app from the task manager.
How can I achieve to read data even in background?
You would have to tap into creating background processes in order to do anything of that nature.
react-native-background-task is probably the easiest way to do that...however, you will not be able to get updated data at such a fast pace as there are numerous limitations, for obvious reasons, to using background tasks.

How to fetch data asynchronously in Cocoa Application using objective C

I am fetching some system information e.g. processor name processor cores and many more and then showing them on NSTextFeild.
The issue is for the time the information is getting fetched, the application hangs.
So, I want to run the task asynchronously.
Note: I have just started with cocoa so please do describe your solution. pretty please..
thanks in advance.
Your UI hangs because you are doing work on the main thread. Hence this is a thread problem. You can then run that fetch for information on another thread, a background thread that doesn't interact with the UI, display something to the user that the data is currently getting retrieved and then, when the data is ready, display it in your NSTextField.
Read more
Understanding dispatch_async
https://developer.apple.com/library/ios/documentation/Performance/Reference/GCD_libdispatch_Ref/

Is there an alternative to BackgroundTask in Windows Phone 8.1?

I have a Windows Phone 8.0 app that I'm porting to 8.1. In 8.0 I depended a lot on BackgroundWorker to execute tasks that I didn't want consuming the UI thread.
I would create the BackgroundWorker, define the DoWork() delegate and then immediately execute RunWorkerAsync()
Now in 8.1 I can't use BackgroundWorker anymore. Instead, I need to create Tasks implementing IBackgroundTask and use IBackgroundTrigger objects run them.
It seems like I need to jump through a lot of hoops just to run code on a different thread. If I want to run a background task immediately to I create a time triggered background task with a new oneShot TimeTrigger() with 0 freshness minutes? That seems like a bit of a hack..
Is there an alternative to BackgroundTask? Should I be approaching my requirements differently?
To run anything on a different thread, all you need to do is call:
Task.Run(delegate() {
// The work to be executed on the background thread
});
You can also await this in a non-blocking way, in case you want to do something after the work in the different thread has finished.
IBackgroundTask is something completely different. It's used when you want to have some code executed on some event when the app is not running. For example, if you want to update the Live Tile every 30 minutes, you would do this using a background task, implementing that interface.

Desing pattern for background working app

I have created a web-service app and i want to populate my view controllers according to the response i fetch(via GET) in main thread. But i want to create a scheduled timer which will go and control my server, if there becomes any difference(let's say if the count of an array has changed) i will create a local notification. As far as i read from here and some google results, i cant run my app in background more then ten minutes expect from some special situations(Audio, Vo-IP, GPS).. But i need to control the server at least one per minute.. Can anyone offer some idea-or link please?
EDIT
I will not sell the app in store, just for a local area network. Let's say, from the server i will send some text messages to the users and if a new message comes, the count of messages array will increment, in this situation i will create a notification. I need to keep this 'controlling' routing alive forever, whether in foreground or background. Does GCD give such a solution do anyone have any idea?
Just simply play a mute audio file in loop in the background, OR, ping the user's location in the background. Yes, that will drain the battery a bit, but it's a simple hack for in-home applications. Just remember to enable the background types in your Info.plist!
Note: "[...] I fetch (via GET) in main thread." This is not a good approach. You should never fetch any network resources on the main thread. Why? Because your GUI, which is maintained by the main thread, will become unresponsive whenever a fetch isn't instantaneous. Any lag spike on the network results in a less than desirable user experience.
Answer: Aside from the listed special situations, you can't run background apps. The way I see it:
Don't put the app in the background. (crappy solution)
Try putting another "entity" between the app and the "server". I don't know why you "need to control the server at least one per minute" but perhaps you can delegate this "control" to another process outside the device?
.
iOS app -> some form of proxy server -> server which requires
"babysitting" every minute.

Exiting application iOS

When my application loads, using the didFinishLaunchingWithOptionsi parse data from the internet to nsarrays. My question is, when the user exists the application by using the 'home' button, and then loads the application again how can the data be re-loaded? (because if the data does not reload - if there are any updates on websites, the new updates will not be seen).
Add an applicationWillEnterForeground method to your app delegate. Load the data there, or start a thread to load it if you like.
You should probably also periodically check for new data even while the app remains open, because the user could go idle for a long time.
As an aside, you shouldn't do anything which might block in applicationDidFinishLaunchingWithOptions. If you are using synchronous NSURLConnection APIs there is a danger the OS might kill your app for taking too long to launch. Best to either use the asynchronous/NSURLConnectionDelegate APIs or do the networking on a background thread and call back to the main thread when you need to update UI (UIKit does NOT like being called from background threads, as it is not thread safe. It might appear to work sometimes, but it will come back to bite you sooner or later).