Mark, your suggestion makes sense.  I tried it.  I created a separate
thread for downloading and uses a Handler to loadUrl instead of
calling loadUrl directly.

But the result is the same.  The loadUrl executions get queued up.  It
appears the downloading thread seems to have priority over the Handler/
UI thread.

Thanks.

On Apr 6, 11:40 am, Mark Murphy <[email protected]> wrote:
> j wrote:
> > I am writing a hybrid web/native app and ran into issue.  My app
> > downloads a music file via Java code, and needs to update a Javascript
> > download progress bar in theWebViewin real time.
>
> > My understanding is the only way to call Javascript from Java is via
> > theWebView'sloadUrl method.
>
> > while ((byteCount = in.read(byteBuffer, 0, BUFFER_SIZE)) != -1) {
> >    out.write(byteBuffer, 0, byteCount);
>
> >    cumByteCount += byteCount;
> >    int percentDowloaded = (cumByteCount * 100) / contentLength;
> >    Log.i(LOG_TAG, "percent: " + percentDowloaded);
> >    webview.loadUrl("javascript:updateDownloadProgress('" +
> > percentDowloaded + "')");
> > }
> > out.flush();
>
> > If so, then while calling Java from Javascript is synchronous, calling
> > Javascript from Java is always asynchronous since loadUrl is
> > asynchronous.
>
> > I notice that all of mywebview.loadUrl calls get queued up and don't
> > get executed until the whole file has been downloaded.  Is there any
> > trick to make thewebviewexecute my javascript immediately instead of
> > queuing everything up?
>
> Sure! Use a thread.
>
> From the looks of your code, my guess is you are doing the download on
> the UI thread. Instead, do the download in a background thread, then use
> Handler or runOnUiThread() or something to get the loadUrl() calls to
> run on the UI thread.
>
> Now, I haven't tried this specifically withWebViewand loadUrl(), but
> you get the results you are seeing from any regular widgets, so I am
> guessing it is the same problem.
>
> --
> Mark Murphy (a Commons 
> Guy)http://commonsware.com|http://twitter.com/commonsguy
>
> Android App Developer Training:http://commonsware.com/training.html
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to