Don´t launch a new Activity when selecting a search suggestion Android

180 views Asked by At

I'm developing an android app, and I've been watching some examples from the sdk, in particular the Dictionary example. The problem is that all this examples launch a new activity when a search suggestion is selected.

The way my app works, that is not good for me, I have to center a map in some point wich is in the background of the same activity with displays the suggestions.

Anyone knows how to catch the intent but not launch an activity?

2

There are 2 answers

0
jbihan On

In the Searchable Dictionary sample, in SearchableDictionay.java you have a method called

private void showResults(String query)

This method displays the results of the search of query in a list. The launch of the activity is triggered when the user clicks on an item in this list, and this is performed in the method

public void onItemClick(AdapterView<?> parent, View view, int position, long id)  

of the listener on the listview :

mListView.setOnItemClickListener(new OnItemClickListener()

If you want to launch your own method, you just have to re-write the code inside that method (for example, to center a map...) :

public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    centerMap();
}

(centerMap() being a method declared in the same class and doing some processing)

0
Javi Martínez On

There is a better and faster way. Simply add:

android:launchMode="singleTop"

In your activity section from AndroidManifest.xml