For reasons too complicated and secret to go into here I’m writing an Adobe AIR application that needs to restart itself occasionally. I didn’t find any clear documents describing how to do this but after some reverse engineering and experimentation, here’s what I came up with.
The air.swf movie that’s used by web pages to install and launch AIR applications calls some internal, undocumented APIs to do this, and so can you!
namespace { import adobe.utils.ProductManager; import mx.core.Application; public class Restart { public static function restart() : void { // request that a new instance of the application be launched new ProductManager('airappinstaller').launch('-launch ' + Application.application.nativeApplication.applicationID + ' ' + Application.application.nativeApplication.publisherID); // exit the current instance Application.application.nativeApplication.exit(0); } } }
I don’t know if or when this will break but it’s pretty straight-forward, once you work it out. It feels to me like there might be some kind of race condition, but it seems to work alright. Oh also, I’ve only tried this on Mac.
I tried to get this and this other example I found here : http://www.hufkens.net/2009/03/how-to-restart-an-air-application-from-code/ to work and have had no luck. Other than making sure that allowBrowserInvocation to true, do you have any other suggestions?
I’m sorry I don’t have any suggestions and I don’t work on this codebase anymore. I heard there were some Flash updates that broke some stuff but I’m not sure if it was this specifically.
it worked when i made its installer (.air) and installed my application otherwise it was just making it close but not restarting..