ãã1ãè¦å¼æ¸
æ¥è¿ä¸ªé®é¢ï¼é¦å
éè¦å¼æç½ä»ä¹æ¯implicit(éè) intentä»ä¹æ¯explicit(æç¡®) intentã
ããExplicit Intentæç¡®çæå®äºè¦å¯å¨çAcitivity ï¼æ¯å¦ä»¥ä¸Java代ç ï¼
ããIntent intent= new Intent(this, B.class)
ããImplicit Intent没ææç¡®çæå®è¦å¯å¨åªä¸ªActivity ï¼èæ¯éè¿è®¾ç½®ä¸äºIntent Filteræ¥è®©ç³»ç»å»çéåéçAcitivityå»å¯å¨ã
ãã2ãintentå°åºåç»åªä¸ªactivityï¼éè¦è¿è¡ä¸ä¸ªå¹é
ï¼ä¸ä¸ªæ¯actionï¼ä¸ä¸ªæ¯categoryï¼ä¸ä¸ªæ¯dataã
ããç论ä¸æ¥è¯´ï¼å¦æintentä¸æå®categoryï¼é£ä¹æ 论intent filterçå
容æ¯ä»ä¹é½åºè¯¥æ¯å¹é
çãä½æ¯ï¼å¦ææ¯implicit intentï¼androidé»è®¤ç»å ä¸ä¸ä¸ªCATEGORY_DEFAULTï¼è¿æ ·çè¯å¦æintent filterä¸æ²¡æandroid.intent.category.DEFAULTè¿ä¸ªcategoryçè¯ï¼å¹é
æµè¯å°±ä¼å¤±è´¥ãæ以ï¼å¦æä½ ç activityæ¯ææ¥æ¶implicit intentçè¯å°±ä¸å®è¦å¨intent filterä¸å å
¥android.intent.category.DEFAULTã
ããä¾å¤æ
åµæ¯ï¼android.intent.category.MAINåandroid.intent.category.LAUNCHERçfilterä¸æ²¡æå¿
è¦å å
¥android.intent.category.DEFAULTï¼å½ç¶å å
¥ä¹æ²¡æé®é¢ã
ããæ们å®ä¹çactivityå¦ææ¥åimplicit intentçè¯ï¼intent filerå°±ä¸å®è¦å ä¸android.intent.category.DEFAULTè¿ä¸ªcategoryã
ããandroid.intent.category.LAUNCHER å
·ä½æä»ä¹ä½ç¨ï¼æå¨xmléé¢å åä¸å æè§æ²¡ä»ä¹åºå«åãè°è½è§£éä¸ï¼
ãã<activity android:name="APAct">
ãã<intent-filter>
ãã<action android:name="android.intent.action.MAIN" />
ãã<category android:name="android.intent.category.LAUNCHER" />
ãã</intent-filter>
ãã</activity>
ãã<activity android:name="URLAct">
ãã<intent-filter>
ãã<category android:name="android.intent.category.LAUNCHER" />
ãã</intent-filter>
ãã</activity>
ããä¸ä¸ªåºç¨ç¨åºå¯ä»¥æå¤ä¸ªActivityï¼æ¯ä¸ªActivityæ¯å级å«çï¼é£ä¹å¨å¯å¨ç¨åºæ¶ï¼æå
å¯å¨åªä¸ªActivityå¢ï¼æäºç¨åºå¯è½éè¦æ¾ç¤ºå¨ç¨åºå表éï¼æäºä¸éè¦ãæä¹å®ä¹å¢ï¼android.intent.action.MAINå³å®åºç¨ç¨åºæå
å¯å¨çActivity android.intent.category.LAUNCHERå³å®åºç¨ç¨åºæ¯å¦æ¾ç¤ºå¨ç¨åºå表é
ããå ä¸ºä½ çç¨åºå¯è½æå¾å¤ä¸ªactivity
ããåªè¦xmlé
ç½®æ件ä¸æè¿ä¹ä¸ä¸ªintent-filterï¼èä¸éé¢æè¿ä¸ªlauncherï¼é£ä¹è¿ä¸ªactivityå°±æ¯ç¹å»ç¨åºæ¶æå
è¿è¡çé£ä¸ªactivityã
ããç°å¨ä½ åªæä¸ä¸ªactivityï¼é£ä¹å ä¸å 就没æå
³ç³»äºã
ããç¨äºæ¨¡æå¨å¯å¨æ¶è®¾ç½®ä¸ºé»è®¤æå¼ä¸ºçactivity
ãã3ã为ä»ä¹å å
¥android.intent.category.DEFAULT
ããæææ¯è¯´ï¼æ¯ä¸ä¸ªéè¿ startActivity() æ¹æ³ååºçéå¼ Intent é½è³å°æä¸ä¸ª categoryï¼å°±æ¯ "android.intent.category.DEFAULT"ï¼æ以åªè¦æ¯æ³æ¥æ¶ä¸ä¸ªéå¼ Intent ç Activity é½åºè¯¥å
æ¬ "android.intent.category.DEFAULT" categoryï¼ä¸ç¶å°å¯¼è´ Intent å¹é
失败ã
ããä»ä¸é¢ç论述è¿å¯ä»¥è·å¾ä»¥ä¸ä¿¡æ¯ï¼
ãã1ãä¸ä¸ª Intent å¯ä»¥æå¤ä¸ª categoryï¼ä½è³å°ä¼æä¸ä¸ªï¼ä¹æ¯é»è®¤çä¸ä¸ª categoryã
ãã2ãåªæ Intent çææ category é½å¹é
ä¸ï¼Activity æä¼æ¥æ¶è¿ä¸ª Intentã
温馨提示:答案为网友推荐,仅供参考