WebView in Your Android Application

Use WebView to load internet content within your application activity

Refer to my previous post of how to do internet activity communication, i will be using WebView in my Second Activity that gets invoked from my main activity

activity_second.xml

<WebView xmlns:android=”http://schemas.android.com/apk/res/android&#8221;
android:id=”@+id/webView1″
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
/>

SecondActivity.java

package com.example.list;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.webkit.WebView;
public class SecondActivity extends Activity {

private String passedVarId = null;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);

passedVarId = getIntent().getStringExtra(“ID”);
WebView webView = (WebView) findViewById(R.id.webView1);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl(passedVarId);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}

Invoking Second Activity from the Main Activity

there is no change here, except pass the url to the page you want to access

Intent i = new Intent(MainActivity.this, SecondActivity.class);
i.putExtra(“ID”, “http://www.cnn.com/&#8221;);
startActivity(i);

Add to AndroidManifest.xml

<uses-permission android:name=”android.permission.INTERNET” />

 

 

Advertisements

One Response to WebView in Your Android Application

  1. Excellent pieces. Keep writing such kind of information on
    your blog. Im really impressed by your blog.
    Hello there, You’ve done an excellent job. I will certainly digg it and for my part suggest to my friends. I am confident they’ll be benefited from this
    site.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: