2

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?

danielrvt-sgb
  • 1,118
  • 5
  • 17
  • 33

2 Answers2

2

There is a better and faster way. Simply add:

android:launchMode="singleTop"

In your activity section from AndroidManifest.xml

Javi Martínez
  • 502
  • 4
  • 10
0

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)

jbihan
  • 3,053
  • 2
  • 24
  • 34