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>
怎樣做才能處理在打開的活動這個意圖?