Android Activity – onNewIntent not being fired

For those of you out there who find their activity is not firing onNewIntent (in the context of creating a searchable activity) there are many things to check such as

  • The activity is being destroyed on a state change such as orientation
  • String literals in the searchable.xml
  • Various others.

I spent a couple of hours going down the wrong track. A heads up might be to check where you  have placed the searchable meta-data in your Android application manifest.

By moving my searchable to the layout directory rather than xml (under res) and moving the meta-data to the activity level in the xml the onNewIntent started to fire and I could respond accordingly

Such as ..

[code language=”java”]

if (Intent.ACTION_SEARCH.equals(intent.getAction())) {

String query = intent.getStringExtra(SearchManager.QUERY);

}

[/code]

In summary make sure the manifest looks something like

[code language=”xml”]

android:theme=”@android:style/Theme.Holo.Light”>;

android:name …

android:configChanges=”orientation|screenSize”

android:label=”@string/app_name”

android:launchMode=”singleTop”>

;

[/code]