Android: Play with WebView

CHEN SU
CS Random Thoughts on Tech
3 min readJan 3, 2018

--

A BRIEF HISTORY

Android WebView has gone through a big change over time.

Before Android 4.4, WebView is based on WebKit, and is shipped in AOSP.

Starting with Android 4.4, WebView is based on Chromium, and is separated from AOSP as a standalone APK (Android System WebView app), which can be updated via Google Play Service.

Since Android 7, WebView is based on Chrome directly, and as long as user upgrades the Chrome app, WebView is upgraded as well.

Developer options

WHY?

Let’s think about bugs. If there’s a bug in WebKit in Android 2.3, the bug is there forever. With Android 4.4, Google’s Chromium team can fix the bug and push the updates via Play Service to eligible devices. With Android 7, Chromium team can fix the bug and submit only to Chrome once, and the change distributes to both Chrome (for any platform), and the WebView as well.

BRIDGE

The most fun part I’ve been playing with WebView so far is the bridge capability between Java and JavaScript. Check out Google docs for details.

JavaScript => Java:

Android” will be the global variable in JavaScript
Bridge from JavaScript to Java

Java => JavaScript

DEBUG

The static method of WebView can enable you to debug through the pages in Chrome via chrome://inspect, just like debugging through a web page.

magic method

--

--