简体   繁体   中英

Why is my searchable activity's Intent.getAction() null?

I've followed the SearchManager documentation yet am still having trouble making one of my app's activities searchable. From my activity, the Search dialog appears, I enter a query, hit search, my activity reopens, then I see this in the log:

D/SearchDialog(  584): launching Intent { act=android.intent.action.SEARCH flg=0x10000000 cmp=com.clinkybot.geodroid2/.views.Waypoints (has extras) }
I/SearchDialog(  584): Starting (as ourselves) #Intent;action=android.intent.action.SEARCH;launchFlags=0x10000000;component=com.clinkybot.geodroid2/.views.Waypoints;S.user_query=sdaf;S.query=sdaf;end
I/ActivityManager(  584): Starting activity: Intent { act=android.intent.action.SEARCH flg=0x10000000 cmp=com.clinkybot.geodroid2/.views.Waypoints (has extras) }
D/WAYPOINTS( 1018): NI Intent { cmp=com.clinkybot.geodroid2/.views.Waypoints (has extras) }
D/WAYPOINTS( 1018): NI null
D/WAYPOINTS( 1018): NI false 

It appears to me that everything is fine up until the last three lines. The "NI" lines are getIntent().toString(), getIntent().getAction() , and getIntent().hasExtra(SearchManager.QUERY) respectively.

ActivityManager appears to be starting my activity with the correct action. Then when my activity starts, it contains no action!? What am I doing wrong?

The relevant portion of my manifest is:

<activity android:name=".views.Waypoints" android:label="Waypoints" android:launchMode="singleTop">
   <intent-filter>
    <action android:name="android.intent.action.SEARCH" />
    <category android:name="android.intent.category.DEFAULT" />
   </intent-filter>
   <meta-data android:name="android.app.searchable"
    android:resource="@xml/searchable" />
  </activity>

That took too many hours of my life. When performing a search from the searchable singleTop activity (in my case Waypoints) you must override onNewIntent() and grab the search query there. Which after a few hours in, I was doing. The catch was that getIntent() does not return the Intent used to call the activity (head explodes). It seems to return the original Intent that opened my searchable activity before I performed my first search .

The onNewIntent method receives the search intent. I replaced getIntent() with the param from onNewIntent() and boom, progress.

Though I must admit; figuring this out eases the frustration of being unable to escape the sound of Dancing with the Stars blaring in the background.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM