I need to put up a context menu in the app when the user selects text
in the WebView. The options in that context menu depend on yes or no
answers I pull from javascript. The content is local content that is
set up to deliver these answers.
if(webView.needsOption1())
// Add option1 to context menu.
I find it strange that this is such a difficult task in Android. I
feel like I'm almost there, I'm just missing something thread related
that causing my web view to lock.
On Jan 18, 11:35 am, Daniel Drozdzewski <[email protected]>
wrote:
> Why does your JS has to be synchronous?
>
> Simply within JS make <body> of your page a throbber and only swap it
> back to its actual content as a last statement in the JS function that
> you want to process.
>
> On 18 January 2012 16:24, tatebn <[email protected]> wrote:
>
>
>
>
>
>
>
>
>
> > I'm getting the same issue using the CountDownLatch. The WebView
> > can't load the url because of the lock.
>
> > On Jan 18, 11:01 am, Streets Of Boston <[email protected]>
> > wrote:
> >> We use a countdown latch instead:
>
> >> String returnValue;
> >> private CountDownLatch latch = null;
>
> >> public String run(String javaScript, int waitInMilliSecs) {
> >> latch = new CountDownLatch(1);
> >> runJS(javaScript); // this method just runs the given javascript in the
> >> WebView.
> >> try {
> >> latch.await(waitInMilliSecs, TimeUnit.MILLISECONDS);
>
> >> } catch (InterruptedException e) { } return returnValue;
> >> }
>
> >> ...
> >> ...
>
> >> // method being called by the javascript in WebView
> >> public void setValue(String value) {
> >> try {
> >> // do your stuff here with 'value':
> >> returnValue = value;}
>
> >> finally {
> >> try { latch.countDown(); } catch (Exception e) {}
>
> >> }
> >> }
>
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Android Developers" group.
> > To post to this group, send email to [email protected]
> > To unsubscribe from this group, send email to
> > [email protected]
> > For more options, visit this group at
> >http://groups.google.com/group/android-developers?hl=en
>
> --
> Daniel Drozdzewski
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en