chufengma / android-skills

android 平时需要注意的小技巧,小构思,小想法。
6 stars 2 forks source link

implicit intent 打开Activity 注意点 #24

Open chufengma opened 8 years ago

chufengma commented 8 years ago

一般都是设置

<activity>
 <action android:name="com.example.demo.XXXX"  />  
</activity>

其它Application中的Activity 调用 startActivity:

Intent intent = new Intent("com.example.demo.XXXX");
startActivity(intent);

这个时候直接启动会失败,往往我们忘记在activity intent-filter中添加:

<activity>
 <action android:name="com.example.demo.XXXX"  />  
 <category android:name="android.intent.category.LAUNCHER" />
</activity>

In order to receive implicit intents, you must include the CATEGORY_DEFAULT category in the intent filter. The methods startActivity() and startActivityForResult() treat all intents as if they declared the CATEGORY_DEFAULT category. If you do not declare it in your intent filter, no implicit intents will resolve to your activity.