I'm currently working on an Android project that heavily relies on the WebView to navigate through multiple HTML pages stored on the device. The inputs entered on these pages are then submitted to the WebView for storage in a database when necessary.
Each page is equipped with controls linked via jQuery for navigation between previous and next pages, and contains various types of input fields like checkboxes and textfields.
The final page features a submit button that utilizes JSInterface to save the results in an SQLite DB, while another button on a customized top navigation bar offers the same functionality.
Users have the ability to edit the results by revisiting the first page where all the saved inputs will be automatically filled using a jQuery system.
To provide more context, I am utilizing SDK 19 and compiling against 4.4.2, although I previously worked with SDK 15 and compiled against 4.2.2 without encountering this issue.
If you'd like to see a simplified version of what I've described, feel free to check out this JSBin.
The Challenge at Hand
I have been using SessionStorage to store inputs across pages as opposed to cookies due to reliability issues with the latter when handling numerous key/value pairs exceeding 150.
However, my concern lies with the fact that the SessionStorage seems to vanish between pages on certain devices.
Testing Procedure
1st Scenario - Staying on the First Page Only
If I remain on the initial page, input data is successfully stored and transmitted upon submission without any setbacks. Revisiting the page for modifications reveals all fields pre-populated with saved information.
2nd Scenario - Navigating Across Pages
Upon filling out page 1 and transitioning to page 2 to enter additional inputs, I cross-check whether the data persists on each individual page during navigation. While all inputs appear intact, only those present on the current page are being sent when submitting the results.
Android Version Test Results
3.2 - Functional
4.1.2 - Not Functional
4.2.1 - Not Functional
4.3 - Not Functional
4.4.2 - Functional
Tried Solutions
Attempted overriding the shouldOverrideUrlLoading method of WebViewClient by returning False - No Positive Outcome
Switching from SessionStorage to LocalStorage yielded no noticeable improvement
Insights Uncovered
Transitioning from sessionStorage to localStorage failed to address the issue effectively.
Valuable insights regarding the WebKit versions employed by Android devices can be found here:
Android 3.2.1 uses an older version (v534.13) yet functions smoothly.
Meanwhile, Android versions ranging from 4.0 to 4.3 share a common WebKit engine version (v534.30).
Android 4.4 deploys a new version (v537.36), explaining its compatibility.
While solutions seem elusive, this insight provides clarity on the problem and affected devices.
Suggested Resolution
Beginning SDK 16, a security setting was introduced to restrict Javascript code from accessing content from diverse origins.
if(Build.VERSION.SDK_INT >= 16) {
setting.setAllowUniversalAccessFromFileURLs(true);
}
Credit goes to ksasq for discovering this solution!
[EDIT 18/02/2014]
Further testing revealed that the issue is tied to TargetSdkVersion, with no influence from BuildTarget adjustments.
When set at 15, WebStorage functionalities operate as intended.
However, if set at 16 or above, WebStorage performance becomes erratic.