0

I open a dialog when the image of a WebView is pressed and then I get this warning. I assume that the WebView is the different thread he is talking about but is there a way to fix this? I simply execute a function when the image is pressed. The function is inside a fragment.

public View onCreateView(....
...
...
    mWebView.addJavascriptInterface(new Object()
    {
        @JavascriptInterface
        public void performClick()
        {
            enlargeImage();
        }
    }, "ok");

private void enlargeImage()
{
    mImageView = new ImageView(getActivity());
    loadImageFromURL(mImage, mImageView);
    loadPhoto(mImageView);
}

here is the loadPhoto function which is giving me the problem.

To be more precise the Dialog is giving the problem. If there is anything I can replace it with it will do as well like a window. What I have and what I want is a window to display a image in which I can close.

Community
  • 1
  • 1
Shishi
  • 601
  • 2
  • 8
  • 27

2 Answers2

0

The callback from javascript will be executed on a background thread, not the UI thread where you can touch the view hierarchy. From your javascript callback (i.e. performClick), you should post a task back to the UI thread.

This documentation should help: http://developer.android.com/training/multiple-threads/communicate-ui.html

ksasq
  • 4,424
  • 2
  • 18
  • 10
0

I needed to place my image code inside :

context.runOnUiThread(new Runnable()
{
   ...
   ...
   ...
});
Shishi
  • 601
  • 2
  • 8
  • 27