Android: Return search query to current activity -


i followed steps described on http://developer.android.com/guide/topics/search/search-dialog.html implement search feature in notepad application.

my problem is, when finish search new activity opens capturing search query. want, query returned current activity instead of starting new one.

is possible?

update:

androidmanifest.xml

  <activity android:name="mynotepad"                   android:label="@string/app_name">             <intent-filter>                 <action android:name="android.intent.action.main" />                 <category android:name="android.intent.category.launcher" />                 <action android:name="android.intent.action.search"></action>             </intent-filter>             <meta-data android:resource="@xml/searchable" android:name="android.app.searchable"></meta-data>         </activity><activity android:name="preferences" android:label="preferences" > </activity>  

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="@string/search_hint"> </searchable>  

java-code

  @override public void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.main_pad);     intent intent = getintent();     if (intent.action_search.equals(intent.getaction())) {         string query = intent.getstringextra(searchmanager.query);         toast.maketext(getapplicationcontext(), query, toast.length_long).show();     } }  
  @override public boolean onoptionsitemselected(menuitem item) {     switch(item.getitemid())     {         case r.id.menuitemsearch:             startsearch("", false, null, false);     break;     }     return true; }  

even if use search-button on phone doesn't work. therefor believe problem in androidmanifest.xml

in application manifest need define current activity searchable activity.

<activity android:name="browseitems" android:label="@string/browseitems"             android:launchmode="singletop">             <intent-filter>                 <action android:name="android.intent.action.search" />             </intent-filter>             <meta-data android:name="android.app.searchable"                 android:resource="@xml/itemsearchable" /> </activity> 

you use following code, http://developer.android.com/guide/topics/search/search-dialog.html#lifecycle

@override public void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.search);     handleintent(getintent()); }  @override protected void onnewintent(intent intent) {     setintent(intent);     handleintent(intent); }  private void handleintent(intent intent) {     if (intent.action_search.equals(intent.getaction())) {       string query = intent.getstringextra(searchmanager.query);       // work using string     } } 

you can use string reload activity, if list activity can call code use load data , use string in that.


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -