Restarting an AIR application

Published:

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.