Android Intent应用

1. 显示Intent

// 直接设置Content和到下一个的Actvity的名字
Intent i = new Intent(MainActivity.this, AnotherAty.class);
startActivity(i);

  2. 隐式Intent

1>. 在AndroidManifest.xml 配置activity时,添加 action中的name属性
<activity android:name=".AnotherAty">
            <intent-filter>
                <!-- 这里的action name 可以写任意的字符串,为了方便使用 用包名加 initent.actioin.AnotherAty (activity名) 组合的形式 -->
                <action android:name="com.aaa.chengzhier.intent.action.AnotherAty" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>


2> 然后在Intent中使用
Intent i = new Intent("com.aaa.chengzhier.intent.action.AnotherAty");
startActivity(i);
配注,不过一般 2> 那样写不怎么方便,可以在第二个 AnotherAty Activity中定义一个静态变量为 com.aaa.chengzhier.intent.action.AnotherAty
public static final String ACTION = "com.aaa.chengzhier.intent.action.AnotherAty"; 
在第一Activity中调用 Intent i
= new Intent(AnotherAty.ACTION); startActivity(i);