Android hybrid development, HTML5 own active update crawl over the pit

Source: Internet
Author: User

There are more and more companies using hybrid development today, and despite the emergence of new technologies, such as Facebook's react native, Ali's Weex, it still doesn't stop some companies from using H5 's determination. Of course, this is also a choice from a variety of considerations.

Three years ago, the use of HTML5 hybrid development, was doing a precious metal software, staff, the universe trading, as well as the information of various stock markets, at that time or on the eve of the outbreak of a bull market, hey ...

The company has recently made use of H5 hybrid development. Some pages and features are H5, initially placed in the local assets directory, and later because the front-end colleagues frequently change and update. In addition to data security considerations, decide to place the package on the server. The interface is used to return a field to infer if updates need to be downloaded. Next, we'll talk about some of the pits we've encountered in development. Make a note for yourself and share it with the friends you need.

First Pit: Android system

For H5 hybrid development, Android system is a big pit, three years ago when the access to H5 point, then a lot of mobile phone cards with PPT-like, 4.0 after Google has done some optimization, the efficiency is really good very much. But then came a series of giant pits. For example, before 4.3 a kernel, 4.3 a separate kernel, 4.3 is a kernel, the original webview can not achieve overall compatibility, finally took a solution. Using the big Penguin's X5 kernel, strengths such as the following:

    1. Inside the class name and method name, and the original name is almost the same, the use of more convenient
    2. QQ and are used X5 kernel, kernel sharing. No need to download separately
    3. Relatively good compatibility

Two pits: Downloadmanager.

The original plan is to use the system under the class Downloadmanager, since it is provided by the system, very many code friends certainly think very ok. But the demolition force, Samsung's mobile phone system has Downloadmanager API deleted. This is disgusting, you still continue to play the explosion ...

Three pits: WebView loading does not show

Before you put it in the assets. Page display is very 6, instead of downloading to the local read, unexpectedly do not display, print the next path, no problem. Then you can be sure that the problem is in the loading process. Checked the information. can be used loaddata. This method requires that the HTML file be read first. Pass in the string to LoadData, can display the page, but does not refer to CSS, JS and other files. can also use Loadurl. Just need to note that this is because the local data is used, so the incoming URL needs to be handled, such as:

    1. Assuming that the HTML file is stored in assets: prefix: file:///android_asset/
    2. Assuming that the HTML file is stored in sdcard: prefix: content://com.android.htmlfileprovider/sdcard/

Ps:content prefixes can cause exceptions, and direct use of file:///sdcard/or File:/sdcard can also

Four pits: escape of special characters

There is a page. iOS colleagues have been showing normal, Android this side is not out, the same page different data page display page. It was very strange at the time, it should not be a H5 point. Or iOS will not show, print the URL to see, wipe, URL has a "%", escaped after the OK. Of course, other special characters need to be escaped on the basis of the need. "%" is just one example.

Five pits: Some phone errors do not show

A WebView method was called on thread ' Javabridge '. All WebView methods must is called on the same thread.

This is because part of the phone WebView method must be on the same thread. by printing Thread.CurrentThread (), you know that you are not part of the same thread. How to resolve:

mWebView.post(new Runnable() {                @Override                publicvoidrun() {                    mWebView.loadUrl("javascript:" + data);                }            });

Code has not been stripped from the company's project, not uploaded at the moment, if there are errors or additions, more generous comments.

Android hybrid development, HTML5 own active update crawl over the pit

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.