Reputation: 543
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.
Upvotes: 1
Views: 812
Reputation: 3339
ImageView img = (ImageView)findViewById(R.id.imageView1);
img.setOnClickListener(new View.OnClickListener()
{
public void onClick(View view)
{
Intent intent = new Intent(Activity1.this,Activity2.class);
intent.putExtra("urlString", "http://www.google.com");
startActivity(intent);
}
});
String url = getIntent().getExtras().getString("urlString");
mWebView = (WebView) findViewById(R.id.webView1);
mWebView.loadUrl(url);
Upvotes: 1