2011-03-11 4 views
1

Google의 Searchable Dictionary 버전을 구현했으며 몇 가지 문제가 있습니다.Android MapView Search 구성 요소가 새로운 의도를 생성하지 않도록 유지

나는 검색하고자하는 기본 ItemizedOverlay가있는 MapView 액티비티에서 구현하고있다. 데이터를 ItemizedOverlay와 동일하게 바꾸 었으며 모든 것이 잘 쿼리 된 것 같습니다.

그러나 목록에서 검색 항목을 선택하면 검색 활동을 시작한 원래 의도가 이벤트를 처리하는 것으로 나타나고 새로운 MapView 의도가 생성되어 똑같은 작업을 수행합니다 (따라서 내가 "뒤로"버튼, 나는 중복 mapView로 돌아 간다.) 열 인덱스가 아닌 그것이 나에게 지점의 위도/경도를 제공합니다 (그래 내가 아는 -

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    setContentView(R.layout.my_map); 

    initializeComponents(); 

    addOverlays(); 

    Intent intent = getIntent(); 

    if (Intent.ACTION_VIEW.equals(intent.getAction())) { 
     // handles a click on a search suggestion; launches activity to show word 
     int lat, lon; 
     Uri uri = intent.getData(); 
     Cursor c = getContentResolver().query(uri, null, null, null, null); 
     try { 
      c.moveToFirst(); 
      lat = Integer.parseInt(c.getString(2)); 
      lon = Integer.parseInt(c.getString(6)); 
     } finally { 
      c.close(); 
     } 

     //this is the ItemizedOverlay that holds the building icons 
     buildingIcons.onTap(new GeoPoint(lat, lon), mapView); 

     Toast.makeText(this, "you searched for " + lat + ", " + lon, Toast.LENGTH_LONG).show(); 
    } 
} 

미친 것은 토스트 통지가 잘 작동된다

내지도보기 클래스는 다음과 같습니다 그것을 검색하는 가장 좋은 방법). 두 번째 MapView 인 텐트가 만들어진 이유에 대한 아이디어가 있습니까?

<searchable xmlns:android="http://schemas.android.com/apk/res/android" 
    android:label="@string/search_label" 
    android:hint="@string/search_hint" 
    android:searchSettingsDescription="@string/settings_description" 
    android:searchSuggestAuthority=".map.DictionaryProvider" 
    android:searchSuggestIntentAction="android.intent.action.VIEW" 
    android:searchSuggestIntentData="content://.map.DictionaryProvider/dictionary" 
    android:searchSuggestSelection=" ?" 
    android:searchSuggestThreshold="1" 
    android:includeInGlobalSearch="true" 
    > 
좋아

답변

0

, 그것을 알아 냈있어 : 경우

은 당신이 그것을 필요로하는 경우에, 여기에 searchable.xml 파일입니다. 문서가 명확하게 표시됩니다

기본적으로 검색 가능한 활동은 onCreate() 호출로 ACTION_SEARCH 인 텐트를 받고 활동의 새 인스턴스가 활동 스택의 맨 위로 이동합니다. 활동 스택에는 검색 가능한 활동의 ​​두 인스턴스가 있습니다. 따라서 BACK 키를 누르면 검색 가능한 활동을 종료하지 않고 검색 가능한 활동의 ​​이전 인스턴스로 돌아갑니다.

당신은 안드로이드 설정 한 경우 : 는 "singleTop"는, 다음 검색 활동 (의도) onNewIntent에 대한 호출과 의도 ACTION_SEARCH 인 를 수신하는 launchMode를, 여기에 새로운 ACTION_SEARCH 의도를 전달합니다.

검색 이벤트를 처리하기 위해 onNewIntent 메소드를 재정의했습니다. 모든 것이 잘 작동합니다!

관련 문제