2011-01-20 47 views
0

我在我的应用程序中实现了一个搜索对话框,我已经为我的活动配置了Intent过滤器,并且已经使用Intent调用了该过滤器,但是同一个活动是我的主要活动,我需要处理已经运行的活动的意图,当事件发生时,我的活动的新实例正在创建,并且再次调用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> 

怎样做才能处理在打开的活动这个意图?

回答