[英]Use the SearchDialog intent to open an active Activity
我在應用程序中實現了搜索對話框,我已經將Intent過濾器配置為我的Activity,並且已經使用Intent調用了該過濾器,但是相同的Activity是我的主要Activity,我需要處理該Activity的意圖已經運行的事件發生時,將創建我的Activity的新實例,並再次調用onCreate。
這是我的代碼。
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>
如何處理已打開的活動的此意圖?
<activity android:name="MainActivity"
android:launchMode="singleTop"
參見http://developer.android.com/guide/topics/search/search-dialog.html
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.