0

OK, I've read every tutorial and stuff on this site, and this should be working. I tried doing this with a previous project and got the same results, so its something I'm missing that's more advanced than a typo.

The search widget appears and seems to be working. However, when the search is submitted, nothing happens. It just sits there. I have tried to override onNewIntent() and onSearchRequested() to add Log.d() output to see if the code is ever called. I've added breakpoints there as well ... nothing! That seems to point to how the Intent is set up in the manifest, but it looks right to me. Maybe another pair of eyes can spot something.

manifest.xml Snippet

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:launchMode="singleTop"
    android:theme="@style/AppTheme" >
    <meta-data android:name="android.app.default_searchable"
        android:value=".DeckView" />
    <activity
        android:name=".DeckView"
        android:label="@string/title_activity_deck_view" >
        <intent-filter>
            <action android:name="android.intent.action.SEARCH" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <meta-data
            android:name="android.app.searchable"
            android:value="@xml/searchable" />
    </activity>

    <activity

xml/searchable.xml

<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
    android:label="@string/search" >
</searchable>

menu/deck_view.xml Note - I have the second search menu calling a dialog of my own which at least lets me search until I get the Android one working. They share actual search-code, just no shared interface.

<menu xmlns:android="http://schemas.android.com/apk/res/android" >

<item
    android:id="@+id/action_settings"
    android:orderInCategory="100"
    android:icon="@android:drawable/ic_menu_preferences"
    android:title="@string/action_settings"
    android:showAsAction="ifRoom"/>
<item android:id="@+id/action_dbops" android:title="@string/maintenance"
    android:icon="@android:drawable/ic_menu_more"
    android:orderInCategory="70" android:showAsAction="ifRoom" />

<item android:id="@+id/menu_search" android:title="@string/search"
    android:icon="@android:drawable/ic_menu_search"
    android:actionViewClass="android.widget.SearchView"
    android:showAsAction="collapseActionView|ifRoom" />

<item android:id="@+id/action_search" android:title="@string/search"
    android:icon="@android:drawable/ic_menu_search"
    android:showAsAction="never" />

<item android:id="@+id/action_help" android:title="@string/help"
    android:icon="@android:drawable/ic_menu_help"
    android:orderInCategory="25" android:showAsAction="ifRoom" />
</menu>

Java source functions .DeckView activity Snippets. Note: I have a call in onCreate that also does handleIntent(getIntent());

@Override
public void onNewIntent(Intent intent) {
    Log.d("TRACE", "New Intent!");
    setIntent(intent);
    handleIntent(intent);
}

@Override
public boolean onSearchRequested() {
    Log.d("TRACE", "ONSEARCHREQUESTED");
    Bundle appData = new Bundle();
    appData.putLong("deck",4);
    startSearch(null, false, appData, false);
    return true;
}

private void handleIntent(Intent intent)
{
    if (intent == null)
        return;

        if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
            long deck;

            Log.d("TRACE","ITS A SEARCH!");
            String query = intent.getStringExtra(SearchManager.QUERY);
            DeckDbHelper dbh = new DeckDbHelper (this,this);
            Bundle appData = getIntent().getBundleExtra(SearchManager.APP_DATA);
            if (appData != null) {
                deck = appData.getLong("deck");
            } else
                deck = 4;
            long id = dbh.createSearchDeck(deck,query);
            Intent newintent = new Intent(this, ShowCard.class);
            intent.putExtra("deckid", String.valueOf(id));
            startActivity(newintent);
        }
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the options menu from XML
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.deck_view, menu);

    // Get the SearchView and set the searchable configuration
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView();
    // Assumes current activity is the searchable activity
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    searchView.setIconifiedByDefault(false); // Do not iconify the widget; expand it by default

    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    if (id == R.id.action_settings) {
        Intent intent = new Intent(this, SettingsActivity.class);
        startActivityForResult(intent, 0, null);
    } else if (id == R.id.action_search) {
        search_options();
    } else if (id == R.id.action_dbops) {
        Intent intent = new Intent(this, DatabaseOps.class);
        startActivityForResult(intent, 0, null);
    } else if (id == R.id.action_help) {
        Intent intent = new Intent(this, ShowCard.class);
        intent.putExtra("deckid", String.valueOf(DeckDbHelper.DECK_HELP));
        intent.putExtra("title", "DeckList");
        startActivity(intent);
    }
    setTarget(null);
    return super.onOptionsItemSelected(item);
}

Any help or insight would be greatly appreciated. I don't think I've ever hit a brick wall this solidly, and I don't even know how to debug this!

Evan Langlois
  • 4,050
  • 2
  • 20
  • 18
  • Does your DeckView Activity extend the `ActionBarActivity`? – brwngrldev May 04 '15 at 19:55
  • Do you have one activity for searching and search reslut? – Aryan Najafi May 04 '15 at 20:00
  • @adavis. No it just extends Activity – Evan Langlois May 04 '15 at 20:17
  • @Aryan - Kinda. The .DeckView activity places an entry in the SQL database that represents a virtual deck (dbh.createSearchDeck) and loads another activity (.ShowCard) that displays the results. This works fine bypassing the widget. The code is never called. – Evan Langlois May 04 '15 at 20:21
  • Ok, you may need to extend the `ActionBarActivity`, see more here: http://stackoverflow.com/a/22714562/2543138 – brwngrldev May 04 '15 at 20:24
  • Is this a guess or an answer? None of my books even mention such a class and none of the documentation from Google or StackOverflow mentions such a requirement. In fact, due to API differences, I've recently removed all references to AppCompat so that I have a clean Google API that should be 100% compatible with published reference materials. Also note that the link you posted says the original question was that the Search wouldn't even show or expand. Mine does (because I'm not using appcompat). – Evan Langlois May 04 '15 at 20:35

0 Answers0