Sample Code for mutual debugging between java and js Code

Source: Internet
Author: User

Java and js methods are used for interdebugging and are often used when HTML5 is used for cross-platform application development. Here, I will share some of my usage in the actual development process, hoping to help beginners.

When using HTML5 for cross-platform application development, it may be difficult for beginners to try the problem that java and js methods are used for interdebugging, here we will share some of your usage in the actual development process, hoping to help you:

First, the js Code calls java code introduction:

Copy codeThe Code is as follows:
Public class CzingLBWebMain extends DroidGap {
@ Override
Public void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
This. loadUrl (file: // android_asset/www/czingIndexHome.html );
WebSettings webSettings = this. appView. getSettings ();
WebSettings. setLoadWithOverviewMode (true );
WebSettings. setSavePassword (false );
WebSettings. setSaveFormData (false );
WebSettings. setsuppzoom zoom (false );
WebSettings. setAllowFileAccess (true );
WebSettings. setJavaScriptEnabled (true );
WebSettings. setPluginState (WebSettings. PluginState. ON );
// Add a java instance to js so that js Code can call java code
This. appView. addJavascriptInterface (this, "appDownloader ");
}
Public void callBackJava (){
}
}


Then, you can directly call the preceding callBackJava () method through window. appDownloader. callBackJava () in the js file referenced by czingindexhome.html.

Then how to call js Code through java code:
The following method is used in java:

Copy codeThe Code is as follows:
String resUrl = "aa ";
String resId = "bb ";
String callBack = "javascript: callBackServive ('" + resUrl + "', '" + resId + "')"; // note the method for passing more than two parameters
This. appView. loadUrl (callBack );


CallBackServive is implemented in js.

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.