Android : Android - sending url from from activity 1 to activity 2 with webView

on Thursday, September 4, 2014


I've got my project here if someone would like to see.


So I want to click image on activity1(which is going to hold link) and then go to second activity with a webview which will open that link. How do I do that? Here is my current code for that, but it crashes the app when I click on image:



//Activity1.java

public void onClick(View view)
{
Bundle bundle = new Bundle();
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.addCategory(Intent.CATEGORY_BROWSABLE);
Intent act2 = new Intent(view.getContext(), Activity2.class);

String url = "http://www.google.com";
bundle.putString("urlString", url);
intent.putExtras(bundle);
startActivity(act2);
}


activity2.java:



//Activity2.java

//OnCreate
String url = super.getIntent().getExtras().getString("urlString");
mWebView = (WebView) findViewById(R.id.webView1);
mWebView.loadUrl(url);

private void load(String url)
{
mWebView = (WebView) findViewById(R.id.webView1);
mWebView.setWebViewClient(new WebViewClient());
mWebView.loadUrl(url);
}


Feel free to check out the whole code here And thank you in advance.


0 comments:

Post a Comment