开发者

Use the SearchDialog intent to open an active Activity

开发者 https://www.devze.com 2023-02-05 13:15 出处:网络
I\'m implementing a Search dialog in my application, I already configured the Intent filter to my Activity, and that is already being called with the Intent, but the same Activity, is my main Activity

I'm implementing a Search dialog in my application, I already configured the Intent filter to my Activity, and that is already being called with the Intent, but the same Activity, is my main Activity and I need to handle the intent on the Activity that was already running, when the event occurs a new instance of my Activity is being created and the onCreate called again.

This is my code.

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 onNewInte开发者_Go百科nt(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);
        }
    }
}

And the Filter:

        <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> 

What to do to handle this intents on the opened Activity?


<activity android:name="MainActivity" 
          android:launchMode="singleTop"

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

0

精彩评论

暂无评论...
验证码 换一张
取 消