2011-01-20 9 views
0

私は自分のアクティビティにインテントフィルタを既に設定していますが、インテントですでに呼び出されていますが、同じアクティビティは私ですmainアクティビティと、既に実行中のアクティビティのインテントを処理する必要があります。イベントが発生してアクティビティの新しいインスタンスが作成され、再度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> 

開いた活動で、このインテントを処理するために何をすべきか?

答えて

関連する問題