20170302
import
android.content.Intent;

import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.co.jp"));
startActivity(intent);
}
}
20160804

--- MainActivity ---
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;

public class MainActivity extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

LinearLayout layout = new LinearLayout(this);
setContentView(layout);
Button button = new Button(this);
button.setText("To SubActivity");
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this,SubActivity.class);
startActivity(intent);
}
});
layout.addView(button);
}
}

--- SubActivity ---
        import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;

public class SubActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
LinearLayout layout = new LinearLayout(this);
setContentView(layout);

Button button = new Button(this);
button.setText("To MainActivity");
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
finish();
}
});
layout.addView(button);
}

}

Web表示 20160804

--- MainActivity ---

import
android.app.Activity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.Toast;

public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
Button btn = new Button(this);
btn.setText("Button");
LinearLayout layout = new LinearLayout(this);
layout.addView(btn, new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT));
setContentView(layout);

btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.co.jp"));
startActivity(intent);
}
});
}
}