A large number of applications make use of a mobile device's ability to access the Internet and one of the most straightforward and flexible ways to do this with Android is through the purpose built WebView viewgroup.
Here we will create a very simple web browser with a back button.
This exercise can be started from scratch, start up a new Android project in Eclipse and add the following permission to the Manifest file:
<uses-permission android:name="android.permission.INTERNET" />
Create a simple layout in the
main.xml
file with a single Button and WebView:<Button android:text="back" android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <WebView android:id="@+id/web_view" android:layout_width="match_parent" android:layout_height="match_parent" />
In the Java activity source declare a WebView field:
WebView webView;
Next, in the
onCreate()
method, set up the Button...