<activity android:name=".SecondActivity"> <intent-filter> <action android:name="hello1" /> <action android:name="hello2" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="category1" /> <category android:name="category2" /> </intent-filter> </activity>
<activity android:name=".ThreeActivity"> <intent-filter> <action android:name="hello1" /> </intent-filter> </activity>
Intent intent = new Intent(); intent.setAction("hello1"); intent.addCategory("category1"); startActivity(intent);
启动一个activity,这个activity的action为hello1,category为category1,必须同时指定action和category 才可以找到对应的activity。只指定action的话,是找配置了
<category android:name="android.intent.category.DEFAULT" /> 的action ,
ThreeActivity是找不到的,Intent是同时找action和category组合,缺一不可
时间: 2024-12-04 18:39:21