FREContext in Java

Opt In Image
Early bird offer on the ANE eBooks


Buy any Easy Native Extensions 2nd Edition package and get our $99 iOS + Android ANE Template completely free before the end of June 2015.



  • step-by-step guide to making your iOS extension in under an hour
  • library for data conversion between ActionScript and native code
  • tutorials
  • infographics
  • code included

In Java FREContext is a class that you extend, which serves as a middleman between ActionScript and your native Java code.

Initializing FREContext

You have to implement two things for your FREContext class to be properly initialized.

The first one, of course, is the constructor. The second one is an implementation of getFunctions():

getFunctions() is how your Java code exposes the native ‘functions’ that AIR can call from ActionScript: you provide an array of their names and instances. Are you wondering why I put functions in quotes? Well, Java being Java, these aren’t functions per se. They are classes of the FREFunction persuasion.



Disposing of (finalizing) FREContext 

Ready for a surprise? Here it comes: all you need for your FREContext class to be tidied up is a destructor.


Surprised? I knew you would be… 

What else?

See the equivalent calls for context initialization and finalization in C.

Next, we’ll attempt to put some order in this bunch of initializers and see a graphic of how this happens and who calls who.

After that it will be the finalization’s turn: we’ll look at the order of calls when an extension is unloaded.

Over to you

At what stage is your ANE at the moment? What’s stopping you from finishing it? Let us know in the comments below.

Warning: count(): Parameter must be an array or an object that implements Countable in /home/easyna6/public_html/easynativeextensions_wp/wp-includes/class-wp-comment-query.php on line 399


    • Hristo

      Hi Igor,

      To be able to call the registerActivityLifecycleCallbacks you have to obtain an instance of the Application class first.

      Here is how to do it from inside a FREContext sub-class:

      • 1. Get the application Activity from the active context.
      • 2. Get the Application owning the Activity.
      • 3. Call the registerActivityLifecycleCallbacks.

      Translated in code:

      Let us know if this works for you.


Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">