In my application i made my content provider searchable, defining my main activity as the default search activity on my manifest.
    <activity
            android:name="com.pt.application.MainActivity"
            android:label="@string/title_activity_map"
            android:launchMode="singleTop"
            android:theme="@style/AppTheme" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.SEARCH" />
            </intent-filter>
            <meta-data
                android:name="android.app.searchable"
                android:resource="@xml/searchable" />
        </activity>
Then i implemented the onSuggestionClick option to update a map, based on the suggestion clicked by the user. The searchview is on the action bar. The problem is that when the user clicks on a suggestion, somehow the activity is recreated (i think OnPause and OnResume are called?). Is there any way to prevent this from happening? I don't want that my activity is "recreated" every time the user clicks on a suggestion.
If more code is needed, please ask. Thanks.
EDIT: Code added
    <?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android" 
    android:label="@string/app_name"
    android:hint="@string/search_hint"
    android:voiceSearchMode="showVoiceSearchButton|launchRecognizer"
    android:voiceLanguageModel="web_search"
    android:searchSuggestAuthority="com.pt.provider"
    android:searchSuggestIntentData="content://com.pt.provider/busstop">
</searchable>
On my main activity:
        // Bind the Activity’s SearchableInfo to the Search View
            searchView = (SearchView)menu.findItem(R.id.menu_search).getActionView();
            this.setupSearchView();
    private void setupSearchView()
        {   
            // Use the Search Manager to find the SearchableInfo related
            // to this Activity.
            SearchManager searchManager =
                    (SearchManager)getSystemService(Context.SEARCH_SERVICE);
            SearchableInfo searchableInfo =
                    searchManager.getSearchableInfo(getComponentName());
            searchView.setSearchableInfo(searchableInfo);
            searchView.setSubmitButtonEnabled(false);
            searchView.setOnSuggestionListener(new OnSuggestionListener() {
                @Override
                public boolean onSuggestionSelect(int position) {
                    return false;
                }
                @Override
                public boolean onSuggestionClick(int position) {
                    // Do things
                    return false;
                }
            });
        }
Solved my question. Changed on the manifest:
From:
android:launchMode="singleTop"
To:
android:launchMode="singleTask"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With