I have two activities “Main” (with a button in it) & “Second”, and I want when I click on the button in Main activity then Second activity should be launched but it should behave like a browser. Means browser should be opened when Second activity is launched.
My code is as follow:
In manifest file I have written
<activity android:name=".Second">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE"/>
</intent-filter>
</activity>
In Main.java file I have written event handler like this
Button b = (Button) findViewById(R.id.button1);
b.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(Main.this, Second.class);
startActivity(intent);
}
});
First of all, is it possible what I want and if yes then am I doing it in right way? And really sorry if I my question is stupid, because I am new to Android
When I started learning about android and its intents I found it very confusing.
But category BROWSABLE in the Manifest does the following.
The target activity can be safely invoked by the browser to display data referenced by a link — for example, an image or an e-mail message.
Read more on: http://developer.android.com/guide/components/intents-filters.html
The two other answers opens the standard web browser and goes to the address specified. If you want a custom browser make the second activity like a web view like this example:
http://www.mkyong.com/android/android-webview-example/
Good luck!