Reprinted: http://sswilliam.blog.163.com/blog/static/189696383201191095759867/
Nativeextension structure and principle
An nativeextension project consists of an as-side library project and an Implementation Project of the underlying code. Taking nativeextension on Android as an example, we will explain a nativeextension project, which is the architecture of the entire nativeextension project.
An nativeextension project consists of the AS library and local implementation.
ActionScript Library Project
In the as Library Project, developers Define the APIs that need to be extended by themselves. The specific implementation of these Apis is mapped to the corresponding Java code.
The core class in the as library project is extensioncontext. Extensioncontext is responsible for interaction with Java code. Extensioncontext calls the createextensioncontext method to create and initialize local Java code. The call method of extensioncontext can call specific Java code and obtain the returned results. Extension also accepts events thrown from Java code.
Java Project
In the Java implementation section, we need to introduce flashruntimeextensions. jar in the airsdk for development. The following authentic freextension, frecontext and frefunction den classes and interfaces are included in the jar package flashruntimeextensions. jar.
Freextension is the entry to Java-side custom code. Freextension is an interface that requires you to override the createcontext method to obtain the context of the local code. The createextensioncontext method of extensioncontext in the as library project calls the getcontext method of freextension to obtain the context of Java code. This call is performed by air
Runtime is complete, and we do not need to care about it.
Frecontext is the provider of the specific content of the local extension. We need to override the getfunctions method to return the specific implementation functions of the local extension. Frecontext also provides some app-related APIs for convenient development. For more information, see the official documentation.
Frefunction is the specific implementation of local methods. Frefunction is an interface that provides the call method. The call method called in the extensioncontext on the as end is mapped to the call method of the specific frefunction.
The getfunctions function of frecontext returns a map whose key is a custom string. value is a specific frefunction. Use the getfunction method. Air
Runtime maps the call (Key, argS) method of the AS end to the call (ARGs) method of the specific frefunctions on the Java end through getfunction. As shown in