Is this the right way to compare intentions?

Is this the right way to compare Intents ? I never get into if / else, regardless of whether the incoming Intent is android.Intent.action.VIEW (intent.getAction () is returned):

  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); } } 

Refresh . Why intent.getAction() return android.Intent.action.VIEW (capital 'i') while it should return android.Intent.action.VIEW , as in the spec ?

+4
source share
1 answer

I discovered where the capital "i" came from. While I am using SearchView , I indicate that Intent will be used when the new Activity SearchView on its own, so I just made a mistake here:

 <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> 
+2
source

Source: https://habr.com/ru/post/1432440/


All Articles