Air native extension on Android-Hello World (2) structure and principle

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.