A hacky little demo project to illustrate how HTML select
(aka drop down) elements for WebView
instances created via a Service
Context
rather than an Activity
cause an application raise an Exception that can't be caught, thus leading to the application being closed.
This table illustrates when this issue occurs:
Nexus 5 | Nexus 7 | |
---|---|---|
HTML select single | Exception | Works |
HTML select multiple | Exception | Exception |
Note: HTML select single
elements display fine on tablets because the items are displayed as part of the page's HTML like so:
Phones display either HTML select
types, and tablets displaying HTML select multiple
elements have issues because WebView (attempts) to display the contents via a Dialog, which can't be created from a Service
without the Intent.FLAG_ACTIVITY_NEW_TASK
flag being passed in.
Logcat of this issue is here.
- WebChromeClient contains functions such as
onJsAlert()
andonJsConfirm()
that applications usingWebView
can override and display in a manner they see fit. It seems reasonable that aonHtmlSelectSingle()
,onHtmlSelectMultiple()
or similiar type functions might be added so 3rd party applications can handle this behavior in the same manner. - WebView/Chromium is configured to check the
Context
that created itself is aService
orActivity
. If the owner is aService
,Intent.FLAG_ACTIVITY_NEW_TASK
could be added to theDialog
that will be spawned so it may display without raising an Exception. - An API function be added so that WebView instances can be configured to behave as they do on tablets, and force such that when a
HTML select
is clicked, the contents are rendered as part of the page itself rather than via aDialog
. This solution would also require tablets to renderHTML select multiple
elements via this embedded rendering rather than falling back to aDialog
.
It's a giant hack that serves only to illustrate the problem described above. MainActivity
spawns MainService
. MainService
creates a WebView
using its Context
. This WebView
is then hackily added to MainActivity
's layout. https://s3.amazonaws.com/linkbubble/test_page.html is loaded, which contains HTML select
elements that when clicked illustrate the issue (as per the table above).