2011-01-20 3 views
0

내 응용 프로그램에서 검색 대화 상자를 구현하고 이미 해당 활동에 인 텐트 필터를 구성했으며 해당 활동은 이미 의도와 함께 호출되고 있지만 동일한 활동은 주요 활동 및 이미 실행중인 활동에 대한 의도를 처리해야합니다. 이벤트가 발생하면 활동의 새 인스턴스가 생성되고 onCreate가 다시 호출됩니다.SearchDialog 인 텐트를 사용하여 활성 활동을 엽니 다.

이것은 내 코드입니다.

public class MainActivity extends Activity { 
    private int ht; 
    private ImageView img; 
    private Bitmap bmp; 

    private int width = 612, height = 792; 

    public void onCreate(Bundle savedInstance) { 
     super.onCreate(savedInstance); 

     requestWindowFeature(Window.FEATURE_NO_TITLE); 
     getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
       WindowManager.LayoutParams.FLAG_FULLSCREEN); 

     setContentView(R.layout.main); 

     img = (ImageView) findViewById(R.id.image01); 
     img.setMinimumHeight(height); 
     img.setMinimumWidth(width); 

     draw(); 
     refreshImage(); 

     handleIntent(getIntent()); 
    } 

    protected void onNewIntent(Intent intent) { 
     setIntent(intent); 
     handleIntent(intent); 
    } 


    private void search(String text) { 
    //Do the search 
    } 


    private void handleIntent(Intent intent) { 
     if (Intent.ACTION_SEARCH.equals(intent.getAction())) { 
      String query = intent.getStringExtra(SearchManager.QUERY); 
      search(query); 
     } 
    } 
} 

그리고 필터 :

 <activity android:name="MainrActivity" 
      android:theme="@android:style/Theme.NoTitleBar.Fullscreen"> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 
       <category android:name="android.intent.category.LAUNCHER" /> 
       <action android:name="android.intent.action.SEARCH" /> 
      </intent-filter> 
      <meta-data android:name="android.app.searchable" 
       android:resource="@xml/searchable" /> 
     </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="Search text..." > 
</searchable> 

열린 활동에서이 텐트를 처리하기 위해 무엇을 할까?

답변

관련 문제