Android Platform PhoneGap Framework Implementation principle

Source: Internet
Author: User

(original) Android Platform PhoneGap Framework Implementation principleCategory: Android2012-03-28 23:10 2919 People read Comments (0) favorite reports PhoneGap Platform Android Frame Apiblackberry

Recently studied the next PHONEGAP mobile phone rapid development framework principle, focused on the Android platform PhoneGap Framework source code, in the reference cutesource write phonegap source analysis, More in-depth understanding of PHONEGAP framework principles, some of which may be helpful in the future, so summarize the key points under the PHONEGAP framework.

1. How does PhoneGap achieve cross-platform?

PhoneGap on every mobile platform (IOS, Android, BlackBerry 、... ) in the implementation of a set of background framework, respectively, and the platform system API to interact to invoke its native API, to the application developers to provide a unified JS call interface, that is, PhoneGap API, developers only need to use HTML, JS, CSS and other web technologies can be quickly developed mobile platform.

PhoneGap's "Write once, run everywhere" means that application development requires only writing front-end code, and can be fully reused to other platforms, and need to be built in a different development environment to run when reusing to other platforms.

2. PhoneGap Framework Implementation principle

Borrowed the original image from the Cutesource article to make a small change, adding the synchronous/asynchronous return process.

Figure PhoneGap Frame schematic diagram

The PHONEGAP framework implementation principle has the following key points:

1) The parsing HTML is rendered based on the browser that is embedded on the mobile terminal WebView, and the Onjsprompt method is emphasized in the webview of the PHONEGAP framework. To capture the front-end business request operation (the prompt action in the EXEC function in the Phonegap.js file) to connect the Web front end to the background Java program.

2) The plugin-based pattern encapsulates the invocation of the native API, which allows the user to extend the custom plugin functionality.

3) The difference between synchronous/asynchronous request operations: WebView captures the requested operation and invokes the corresponding plugin according to the captured parameters.

In the case of a synchronous request, the result is immediately returned to the front end, which is the Phonegap.js file exec function

var r = prompt (Json.stringify (args), "Gap:" +json.stringify ([Service, Action, Callbackid, True]); The return result of the call is immediately obtained;

In the case of an asynchronous request, the result is stored in the callback linked list, which is passed through the XHR channel to the front end, which is the Phonegap.js file Phonegap.jscallback function

var msg = decodeuricomponent (xmlhttp.responsetext); The return result of the call is obtained.

4) Callbackserver Monitoring service Thread

The Callbackserver thread starts when the PHONEGAP framework is first loaded, and then listens to the front-end XHR requests and data in the linked list, and when there is a XHR request, the thread waits up to 10s if the list is empty, and in the waiting process if there is data in the list, Will wake up the waiting thread, which immediately passes the data in the list to the front end, and if there is no data after 10s, the empty data is returned to the front end, thus initiating the next round of XHR requests; This is the so-called "server-based push technology" model. such as PhoneGap in the streaming chart.

Figure PhoneGap Data Flow chart

3. Extensions custom feature plug-in development considerations:

custom plug-in class when inheriting plugin, consider overriding its Issynch method and its asynchronous/synchronous return value, otherwise there is a problem when using a custom plug-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: 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.