* startActivity(intent);
public class StartSystemActivity extends Activity implements OnClickListener{ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_start_system); Button btn_switch1 = (Button) findViewById(R.id.btn_switch1); btn_switch1.setOnClickListener(this); Button btn_switch2 = (Button) findViewById(R.id.btn_switch2); btn_switch2.setOnClickListener(this); Button btn_switch3 = (Button) findViewById(R.id.btn_switch3); btn_switch3.setOnClickListener(this); Button btn_switch4 = (Button) findViewById(R.id.btn_switch4); btn_switch4.setOnClickListener(this); } @Override public void onClick(View v) { Intent intent = new Intent(); switch(v.getId()){ case R.id.btn_switch1: intent.setAction(Intent.ACTION_VIEW); Uri uri = Uri.parse("http://www.sina.com"); intent.setData(uri); startActivity(intent); break; case R.id.btn_switch2: intent.setAction(Intent.ACTION_GET_CONTENT); intent.setType("image/*"); startActivity(intent); break; case R.id.btn_switch3: intent.setAction(Intent.ACTION_SEND); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_TEXT, "这是一条短信!"); startActivity(intent); break; case R.id.btn_switch4: intent.setAction(Intent.ACTION_VIEW); Uri uri2 = Uri.parse("tel:10010"); intent.setData(uri2); startActivity(intent); break; } } }
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.imooc.activitystudy.OneActivity" > <Button android:id="@+id/btn_switch1" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="启动浏览器" /> <Button android:layout_below="@id/btn_switch1" android:id="@+id/btn_switch2" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="启动相册" /> <Button android:layout_below="@id/btn_switch2" android:id="@+id/btn_switch3" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="启动短信" /> <Button android:layout_below="@id/btn_switch3" android:id="@+id/btn_switch4" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="启动电话界面" /> </RelativeLayout>