TKV
TKV

Reputation: 2663

android webview url loading twice

Hi am facing a strange problem related to android webview.

Am having a webview component in a layout. and in the onCreate method of Activity am loading that webview with a url, appending some parameters. I think at first this call is happening, but immediately after that call again a call is going to load the webview. And in the 2nd call, parameters not getting appended to the URL, because of this webview is not loading properly as expecting..

Can anyone help me to solve the issue.?

Upvotes: 1

Views: 2078

Answers (1)

Ponmalar
Ponmalar

Reputation: 7031

Check with this

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.webkit.WebView;

public class StackOverFlowActivity extends Activity {

    private Handler mHandler = new Handler();

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        WebView view=(WebView)findViewById(R.id.webView1);
        view.getSettings().setJavaScriptEnabled(true);
        view.loadUrl("file:///android_asset/index.html");
        view.addJavascriptInterface(new MyJavaScriptInterface(), "Android");
    }

    final class MyJavaScriptInterface
    {
        public void ProcessJavaScript(final String scriptname, final String args)
            {             
                mHandler.post(new Runnable()
                    {
                        public void run()
                            {
                    String url="file:///android_asset/img.jpg";
                                webview.loadUrl("javascript:image(\""+url+"\")");
                            }
                    });
            }
    }
}

For more Details: Trying to append an image in android webview

Upvotes: 2

Related Questions