a. 在A的onCreate方法中首先調用super. onCreate(),
public void onCreate(Bundle savedInstanceState) { … root = new LinearLayoutSoftKeyboardDetect(this, width, height); …}public void init() { CordovaWebView webView = new CordovaWebView(DroidGap.this); this.init(webView, new CordovaWebViewClient(this, webView), new CordovaChromeClient(this, webView));}public void init(CordovaWebView webView, CordovaWebViewClient webViewClient, CordovaChromeClient webChromeClient) { this.appView = webView; this.appView.setId(100); … this.root.addView(this.appView); setContentView(this.root);}public void loadUrl(String url) { if (this.appView == null) { this.init(); } …}
public void onCreate(Bundle savedInstanceState) { super. onCreate(Bundle savedInstanceState); setContentView(resID); …}
c. 在執行個體化CordovaWebView的時候, CordovaWebView對象會去建立一個屬於當前CordovaWebView對象的外掛程式管理器PluginManager對象,一個訊息佇列NativeToJsMessageQueue對象,一個JavascriptInterface對象ExposedJsApi,並將ExposedJsApi對象添加到CordovaWebView中,JavascriptInterface名字為:_cordovaNative。
public void handleResume(boolean keepRunning, boolean activityResultKeepRunning){ // Send resume event to JavaScript this.loadUrl("javascript:try{cordova.fireDocumentEvent('resume');}catch(e){console.log('exception firing resume event from native');};"); // Forward to plugins if (this.pluginManager != null) { this.pluginManager.onResume(keepRunning); } // Resume JavaScript timers (including setInterval) this.resumeTimers(); paused = false;}