Tuesday, December 15, 2009

[android-developers] Re: Forward search queries to one single activity that handles search

Take a look at the SearchManager stuff:
http://developer.android.com/reference/android/app/SearchManager.html

From what I can see you only want one activity that responds to the
search, the others need to be able to initiate (I think) what would be
a 'local search'
When you start a search the system it always going to create an
instance of those classes which have the filter so they can process
they search intent.


On Dec 15, 2:38 pm, Stefan Klumpp <stefan.klu...@gmail.com> wrote:
> Your assumption is partly right.
>
> I want all activities to accept search queries (via the search button
> on the phone), although I want only one single activity to handle the
> search (via a web server) and display the results.
>
> The problem is now, to make all activities accept search queries.
> Therefor I have to add the <intent filter> to all activities,
> otherwise pressing the search button will only show up the default
> Google Search, but not my custom search.
>
> But having the <intent filter> in each activity causes to create a new
> instance (at least onCreate() is called) of that activity, whenever I
> enter a String and start the search. And that is what I'd like to
> avoid.
>
> My goal is to have all activities accept search input (meaning
> pressing the search button opens up the search box), but then as soon
> as the search gets started it should be handled by the one single
> search activity.
>
> I hope that helps to better understand my problem.
>
> On Dec 15, 1:50 pm, MrChaz <mrchazmob...@googlemail.com> wrote:
>
>
>
> > As I understand it you only want the intent-filter in the activity
> > that does the searching.  The intent filter says the to platform "hey
> > I can do this"
> > Then in the activities you want to use the search you can
> > startActivityForResult()
>
> > On Dec 15, 12:11 pm, Stefan Klumpp <stefan.klu...@gmail.com> wrote:
>
> > >  have an activity handling search (ACTIVITY_1), which works perfectly
> > > when I use the search (via SEARCH button on the phone) within/from
> > > this activity.
>
> > > However, when I use search from another activity (ACTIVITY_2..x) by
> > > implementing onNewIntent and forward the query string to my
> > > Search_Activity.class (ACTIVITY_1) it always pauses ACTIVITY_2 first
> > > and then goes to onCreate() of ACTIVITY_2.
>
> > > @Override
> > > protected void onNewIntent(Intent intent) {
> > >     Log.i(TAG, "onNewIntent()");
>
> > >     if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
> > >         Log.i(TAG, "===== Intent: ACTION_SEARCH =====");
> > >         Intent myIntent = new Intent(getBaseContext(),
> > > Search_Activity.class);
> > >         myIntent.setAction(Intent.ACTION_SEARCH);
> > >         myIntent.putExtra(SearchManager.QUERY, intent.getStringExtra
> > > (SearchManager.QUERY));
> > >         startActivity(myIntent);
> > >     }
>
> > > }
>
> > >     * Why does it recreate my ACTIVITY_2 when it is already there and
> > > doesn't go to onNewIntent directly?
> > >     * Is there another way I can forward search queries directly to
> > > ACTIVITY_1? For example via a setting in the Manifest.xml
> > >     * Is it possible to generally forward all search queries
> > > automatically to ACTIVITY_1 without even implementing onNewIntent in
> > > all the other activities?
>
> > > Currently I have to put an <intent-filter> in every single activity to
> > > "activate" my custom search there and forward the query then to the
> > > activity that handles search via the onNewIntent (as shown above).
>
> > > <activity android:name=".Another_Activity"
> > >     android:theme="@style/MyTheme">
> > >     <intent-filter>
> > >         <action android:name="android.intent.action.SEARCH" />
> > >         <category android:name="android.intent.category.DEFAULT" />
> > >     </intent-filter>
> > >     <meta-data android:name="android.app.searchable"
> > >         android:resource="@xml/searchable" />
> > > </activity>

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate