Activity显示/隐式调用,主要通过intent-filter实现
其中category的各项属性值及含义
常量 | 含义 |
CATEGORY_BROWSABLE | 目标activity可以使用浏览器来显示-例如图片或电子邮件消息. |
CATEGORY_GADGET | 该activity可以被包含在另外一个装载小工具的activity中. |
CATEGORY_HOME | 该activity显示主屏幕,也就是用户按下Home键看到的界面. |
CATEGORY_LAUNCHER | 该activity可以作为一个任务的第一个activity,并且列在应用程序启动器中. |
CATEGORY_PREFERENCE | 该activity是一个选项面板. |
package com.test;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
/**
* @author WonderCoder
* @time 2012-3-30
* Activity间的切换
*
*/
public class MainActivity extends Activity implements OnClickListener {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button bt1 = (Button)findViewById(R.id.button1);
Button bt2 = (Button)findViewById(R.id.button2);
Button bt3 = (Button)findViewById(R.id.button3);
bt1.setOnClickListener(this);
bt2.setOnClickListener(this);
bt3.setOnClickListener(this);
}
public void onClick(View view) {
Intent intent = null;
switch(view.getId()){
case R.id.button1:
intent = new Intent(this,MyActivity1.class);
break;
case R.id.button2:
intent = new Intent("myaction1");
break;
case R.id.button3:
intent = new Intent("myaction2");
intent.addCategory("mycategory");
break;
}
startActivity(intent);
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button android:text="显示调用Activity"
android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</Button>
<Button android:text="隐式调用Activity"
android:id="@+id/button2"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</Button>
<Button android:text="隐式调用两个符合过滤条件的Activity"
android:id="@+id/button3"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</Button>
</LinearLayout>
运行结果: