0

I have implemented my search widget in the Main Activity.. And my MainActivity is handling all the searching feature.. When the query is executed the results are come up as per desired.. But the real problem is while the search query result are visible if i want to go back to the basic MainActivity contents then i try pressing the Home/Up button or device Back button... On pressing Home/Up button nothing happens.. simply the open search widget collapse... but on pressing the Back button the app exits..

What i want is.. I would like to return to the basic on start results in MainActivity without exiting the app after search contents are shown..

Here is my Manifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.pockettutsforcosm"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="11"
    android:targetSdkVersion="20" />

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:launchMode="singleTop"
        android:parentActivityName=".MainActivity" >
        <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>

    <meta-data
        android:name="android.app.default_searchable"
        android:value=".MainActivity" />
</application>

</manifest>

UPDATE MainActivity Source-

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    if (!mNavigationDrawerFragment.isDrawerOpen()) {
        // Only show items in the action bar relevant to this screen
        // if the drawer is not showing. Otherwise, let the drawer
        // decide what to show in the action bar.
        getMenuInflater().inflate(R.menu.main, menu);

        // Associate searchable configuration with the SearchView
SearchManager searchManager =(SearchManager)getSystemService(Context.SEARCH_SERVICE);
SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
        // Assumes current activity is the searchable activity
searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
        // Do not iconify the widget; expand it by default
        searchView.setIconifiedByDefault(false);
        searchView.setSubmitButtonEnabled(true);
        restoreActionBar();
        return true;
    }
return super.onCreateOptionsMenu(menu);}

I am handling it using the following code-

@Override
protected void onNewIntent(Intent intent) 
{
    setIntent(intent);
    handleIntent(intent);
}

private void handleIntent(Intent intent) {
    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        String searchText = intent.getStringExtra(SearchManager.QUERY);
        doMySearch(searchText);

        // Do work using string

    }
}

private void doMySearch(String searchText)
{
    c = dbOpen.getMySearchFromDB(searchText);
    showListContent(c);
}

i am calling- handleIntent(getIntent); in onCreate() of MainActivity

user3794646
  • 23
  • 1
  • 10

0 Answers0