Используйте намерение SearchDialog, чтобы открыть активное действие - PullRequest
0 голосов
/ 20 января 2011

Я внедряю диалоговое окно поиска в своем приложении, я уже настроил фильтр Intent для своей Activity, и он уже вызывается с Intent, но эта же Activity является моей основной Activity, и мне нужно обработать намерение в действии, которое уже выполнялось, когда происходит событие, создается новый экземпляр моего действия и снова вызывается onCreate.

Это мой код.

public class MainActivity extends Activity {
    private int ht;
    private ImageView img;
    private Bitmap bmp;

    private int width = 612, height = 792;

    public void onCreate(Bundle savedInstance) {
        super.onCreate(savedInstance);

        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);

        setContentView(R.layout.main);

        img = (ImageView) findViewById(R.id.image01);
        img.setMinimumHeight(height);
        img.setMinimumWidth(width);

        draw();
        refreshImage();

        handleIntent(getIntent());
    }

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


    private void search(String text) {
    //Do the search
    }


    private void handleIntent(Intent intent) {
        if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
            String query = intent.getStringExtra(SearchManager.QUERY);
            search(query);
        }
    }
}

И Фильтр:

        <activity android:name="MainrActivity"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
                <action android:name="android.intent.action.SEARCH" />
            </intent-filter>
            <meta-data android:name="android.app.searchable"
                android:resource="@xml/searchable" />
        </activity>

The searchable.xml

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

Что делать, чтобы справиться с этими намерениями в открытой Деятельности?

1 Ответ

1 голос
/ 23 сентября 2011
<activity android:name="MainActivity" 
          android:launchMode="singleTop"

см. http://developer.android.com/guide/topics/search/search-dialog.html

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...