In Android development, with the development efficiency and interface updates in mind, sometimes using webview combined with Web page technology, mobile applications can be quickly and iteratively developed. WebView load resources is not slow, but if there are more resources, it is slow. Pictures, CSS, JS, html each of these resources will probably need to 10-200ms, generally 30ms or less on the line. However, WebView is waiting for all the resources to be loaded to finish the rendering, so finally use native JS to write, do not use too much jquery and other frameworks, to improve the user experience.
In hybrid development, the Android native SDK is sometimes used, such as calling a camera, viewing an album, recording, and so on, which requires JavaScript in the Web page to be called to the Android SDK interface. Because Android's WebView is based on the WebKit kernel, it integrates the interface functions of JS and Java intermodulation, which can be easily used for development.
Code:
1 <Relativelayoutxmlns:android= "Http://schemas.android.com/apk/res/android"2 Xmlns:tools= "Http://schemas.android.com/tools"3 Android:layout_width= "Match_parent"4 Android:layout_height= "Match_parent" >5 6 <WebView7 Android:id= "@+id/webview"8 Android:layout_width= "Fill_parent"9 Android:layout_height= "Fill_parent"Ten Android:layout_above= "@+id/linearlayout" One /> A <LinearLayout - Android:id= "@+id/linearlayout" - Android:layout_width= "Match_parent" the Android:layout_height= "Wrap_content" - Android:layout_alignparentbottom= "true" - > - <Button + Android:id= "@+id/btn" - Android:layout_width= "Wrap_content" + Android:layout_height= "Wrap_content" A Android:text= "Java invoke JavaScript interface" at > - </Button> - </LinearLayout> - </Relativelayout>
Java and JavaScript interaction on WebView