Relaunch WinRT app when suspended - windows-runtime

I have a personal WinRT app I'm working on, and when the app is suspended, I would like to have it relaunch itself with different launch parameters.
I know you can kind of already do this with toast notifications, but I would like to know if it's possible to do without any user interactions.
Thanks!

Wow. I never thought of this before. Your only hope would have been to re-launch your application during the suspending event using protocol activation. But what happens is it is not re-launched, it is reactivated while in the suspending state and the activation is denied. You can't delay the re-activation either because all thread schedules are suspended once the app is terminated, too. I tried this in a test app just now and I'm right.
There's also no option with somehow triggering a background task. Though the ApplicationTrigger is coming with Windows 10, the rule still remains that a background task cannot invoke any UI. So, you can't use a background task.
Then I thought about file activation. Then I realized that file activation is identical to protocol activation and the result would be the same, too.
Yes, the idea of using a timed toast or scheduled reminder would sort of work. It would certainly require the user to tap the toast, and if toast were disabled, or the user didn't tap them (they are transient), you are left not running and nothing going to start you.
There is one more thing you can do. Since there isn't a WinRT solution here, remember there's almost always a Win32 solution. There is nothing wrong with a Win32 in-memory app listening for your app to be terminated and starting it again (like by using protocol activation). Your problem is solved unless you are running this on an ARM device - hopefully not.
I talk about protocol activation here:
http://blog.jerrynixon.com/2012/10/walkthrough-using-windows-8-custom.html
Best of luck!

Related

Windows Phone 8 prevent the app from ever being re-activated and restart on next launch

I've got a big code base we just migrated to phone and are beginning to deal with tombstoning and deactivation. In the meantime I'd like to stop the app on Application_Deactivated so that it will call Application_Launching rather than Application_Activated when reactivating from tombstone. Anyone know of a way to accomplish this?
As far as i know, you should not intervene in the application cycle and let OS handle things. I read that you should not use the following functionality. It is not advised to use it. Though, this is a way ::
Application.Current.Terminate();
Add this line to your Application_Deactivated handler. This will terminate and kill your application. But then you won't find your app in the background. You will have to launch it freshly the next time you want to use it.
If this is not what you want, and you wish exactly to restart the application on bringing it to foreground, then i don't see any direct way to do that.
Thanks and cheers.

Windows Phone 8 - Keeping background location tracking active beyond four hours

I'm in the process of developing a WP8 app that makes use of the background location tracking abilities provided by the OS. The idea is to monitor the users position and to notify them when they are near certain types of places.
So far it all seems to work fine and when running the location tracking works as I would expect.
The problem is, it seems that the phone times out background apps after around four hours, stopping the location tracking.
I can understand why Microsoft did it, to preserve battery life etc. But there's not much point having a background location tracking app that has to be manually restarted every four hours! If a user chooses to run this app and is made aware of the potential battery hit, surely it should be able to run indefinitely - to a point of course, if the system runs out of resources or similar then that's fair enough.
Does anyone have any experience with this? There must be hundreds of others apps in the store that have run into this issue I would have thought? And presumably there must be some way of keeping the location tracking running?
I've tried periodically updating the live tile (using a DispatcherTimer) while the tracking is running but this doesn't seem to be enough to keep the app alive either :(
Anyone have any ideas?
Thanks.
There is no way to achieve your desired behavior. The app will be deactivated under anye of following conditions:
The app stops actively tracking location. An app stops tracking location by removing event handlers for the PositionChanged and StatusChanged events of the Geolocator class or by calling the Stop() method of the GeoCoordinateWatcher class.
The app has run in the background for 4 hours without user interaction.
Battery Saver is active.
Device memory is low.
The user disables Location Services on the phone.
Another app begins running in the background.
Source: Running location-tracking apps in the background for Windows Phone 8
What you could do is to show a toast notification before app is deactivated advising the user, and make him navigate back to the app, extending the period for other 4 hours that way.
There is no way to keep it running without any user interaction.

How close WinRT app after fatal error

I am searching for a nice way how to close an WinRT app after fatal error.
This should be used only in last chance error handlers TaskScheduler.UnobserveTaskExcption and App.UnhandledException where I obviously failed to handle it correctly on right places. Should never happen, but...
Desired behaviour: Application should then show 'Sorry' message, log the exception and after user clicks Ok button, app should be closed.
I searched for solutions and lot of results points me, that WinRT must not be closed programmatically. Eg. here programatically close win8 app .
When I call Exit method, app is closed, but afterwards exceptions are thrown, like could not do this and that because app is closing...etc.. Makes me kind of nervous.
How would you solve my problem? It has no sence to keep the app running after unhandled exception, and let it crash by setting Handled = false is not good solution as well I thing. Beside this UnobservedExceptions does not trigger crash. I heard that apps with crashes will be removed from store.
Thx for your ideas!
Referring to the application lifecycle provided by Microsoft, the app should terminate without any warning and return the user to the Start screen.
http://msdn.microsoft.com/en-us/library/windows/apps/hh464925.aspx#app_crash
You should not be closing apps which target the Windows Runtime at all. The app lifecycle management system built-in takes into account many factors including usage statistics and current system resources and will almost certainly make better decisions about when to close apps than you will.

How can I pre-start my RAP application to trigger warmup right after startup

I have a RAP application which we deploy into a Tomcat instance. The application does some additional stuff during it's first startup.
Currently when the first user opens the webpage in a Browser, it takes quite a while until the application is ready because of this one-time initialization work.
This is bad for usability as the first user needs to wait a long time until this startup-work is done.
Is there a way to trigger or simulate a first session after the Tomcat is started so we can warmup the application and the first user receives feedback quickly?
I tried to do some simple URL-requests via URLConnection to simulate a browser, but it seems the protocol to trigger a new session is non-trivial.
I also tried to use HtmlUnit to request the page with JavaScript enabled, this works to some degree, but HtmlUnit is quite heavy for this simple step.
So is there an official API or at least some sort of workaround that allows me to pre-start and initialize the application?
Unless this initialization requires a UI session (i.e. a user), the configure method of your ApplicationConfiguration could be a suitable place. However, at this point, the ApplicationContext has not been completely set up, so it could be too early. Also, if your application is based on the workbench and extension points, you won't have an ApplicationConfiguration of your own.
Would you mind opening a bug report (http://eclipse.org/rap/bugs) and describe your use case? I think we should provide some kind of hook for applications to setup and clean up, e.g. an ApplicationContextListener?

How does Battlelog launch games from browser?

Battlelog was released by EA alongside Battlefield 3 recently, and I'm curious how it is able to launch games, such as Battlefield 3, from a web browser?
More generally, how does a website launch programs locally?
I'm one of the developer responsible for the launch part of Battlelog. It's handled by a combination of the installed web browser plugin and JavaScript. Launching the game basically goes through these steps.
We figure out where you've installed the BF3.exe by using a registry key
We use the plugin to launch that exe with a couple of command line options
When the game client has launched, it opens a connection back to the plugin, for two-way communication between Battlelog and the game.
Game client sends state info and error messages back through the connection, so we can show progress and errors in Battlelog, and also know when the game has closed down.
It is thanks to the plugin you installed at battlelog. Websites are not allowed to execute programs on your local machine due to the HUGE security risk that would present. Plugins have to be used if you want to accomplish virtually anything outside the context of the browser, which is why you have to explicitly give them permission to install when they try to run.
I think that there are two options. First, the link points to a file which has an extension understandable only to that program, like when you click a .pdf link a pdf viewer will open. My second guess is that the link may use another protocol associated to the program in question, does the link start really with http://?
Im almost 100% sure it uses the plugin you have to install to manage the launch process as it also controls whether the game is minimised or not.