android – 这是比较Intents的正确方法吗?

这是比较Intents的正确方法吗?我永远不会进入if / else,无论传入的Intent是
android.Intent.action.VIEW(值intent.getAction()返回):

    private void handleIntent(Intent intent) {
Log.d(TAG, intent.getAction()); // -> android.Intent.action.VIEW
            if (Intent.ACTION_VIEW.equals(intent.getAction())) {
                ShowToast.showToast(this, "Something..."); // Never get here
            } else if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
                String query = intent.getStringExtra(SearchManager.QUERY);
                showResults(query);
            }
        }

更新:为什么intent.getAction()返回android.Intent.action.VIEW(大写’i’),而它应该像specification一样返回android.intent.action.VIEW?

最佳答案 我找到了首都“我”的来源.只要我使用SearchView,我就指定当我自己开始新Activity时要使用的Intent,所以我在这里犯了一个错误:

<searchable xmlns:android="http://schemas.android.com/apk/res/android"
            android:label="@string/appname"
            android:hint="@string/search_hint"
            android:searchSuggestAuthority="my.package.dataproviders.TicketSuggestionProvider"
            android:searchSuggestIntentData="content://my.package.dataproviders.TicketSuggestionProvider/titleslist"
            android:searchSuggestIntentAction="android.Intent.action.VIEW" // HERE IT IS
            android:searchSuggestSelection=" ?">
</searchable>
点赞