![](/img/trans.png)
[英]Failed to start an activity with implicit intent and had added category in xml
[英]Failing to start an activity with an implicit intent
我有些困惑,為什么隱式意圖調用失敗了。 嘗試啟動意圖時,我不斷收到以下錯誤:
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=content://org.chrisolsen.crossfit.providers.WorkoutProvider/workouts typ=vnd.android.cursor.dir/vnd.chrisolsen.crossfit.workout }
Android清單
<activity android:name=".activities.WorkoutsActivity"
android:label="@string/title_workouts" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<data android:mimeType="vnd.android.cursor.dir/vnd.chrisolsen.crossfit.workout"/>
</intent-filter>
</activity>
<provider
android:name=".providers.WorkoutProvider"
android:authorities="org.chrisolsen.crossfit.providers.WorkoutProvider" />
通話活動(儀表板)
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(WorkoutProvider.CONTENT_URI, "vnd.android.cursor.dir/vnd.chrisolsen.crossfit.workout");
startActivity(intent);
稱為活動(鍛煉)。 它不在這里
Uri uri = getIntent().getData();
...
看起來應該很簡單,但是我對為什么沒有活動發現感到困惑。
有任何想法嗎?
為了以隱式意圖開始,活動必須聲明
<category android:name="android.intent.category.DEFAULT" />
另外,請確保您使用的是startActivity
而不是sendBroadcast
。 這些方法之間有區別。 活動的意圖過濾器將不會接收廣播。 您必須為此使用BroadcastReceiver
。
請注意,盡管Intent類用於發送和接收這些廣播,但此處的Intent廣播機制與用於通過Context.startActivity()啟動Activity的Intent完全分開。 BroadcastReceiver無法查看或捕獲與startActivity()一起使用的Intent; 同樣,當您廣播意圖時,您將永遠找不到或開始活動。 這兩個操作在語義上有很大不同:使用Intent啟動Activity是修改用戶當前正在與之交互的前台操作; 廣播Intent是用戶通常不知道的后台操作。
來源: http : //developer.android.com/reference/android/content/BroadcastReceiver.html
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.