[英]onCreate() or onNewIntent() not fired when search button pressed
I'm trying to implement search functionality in my app, which is very basic at the moment. 我正在尝试在我的应用中实现搜索功能,这在目前非常基础。 When I press the search button on my Nexus, the search intent seems to not fire because neither onCreate() nor onNewIntent() gets called. 当我按下Nexus上的搜索按钮时,搜索意图似乎没有触发,因为onCreate()和onNewIntent()都没有被调用。 I have basically copied the whole example you can find on Android developers , but it is still not working. 我基本上复制了你可以在Android开发者身上找到的整个例子,但它仍然没有用。 Thanks for your help 谢谢你的帮助
res/searchable.xml RES / searchable.xml
<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:label="hello"
android:hint="Search lectures" >
</searchable>
AndroidManifest.xml AndroidManifest.xml中
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.openday.lectures"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="7" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".LecturesListActivity"
android:label="@string/app_name"
android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="@xml/searchable"/>
</activity>
<activity android:name=".SingleLectureActivity"
android:label="Lecture">
</activity>
</application>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
</manifest>
LecturesListActivity.java (shortened) LecturesListActivity.java(缩写)
public class LecturesListActivity extends ListActivity {
private String categoryDisplayed;
private String facultyDisplayed;
private List<Lecture> lectures;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
loadLectures();
displayFaculties();
}
@Override
protected void onNewIntent(Intent intent) {
setIntent(intent);
handleIntent(intent);
}
private void handleIntent(Intent intent) {
if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
String query = intent.getStringExtra(SearchManager.QUERY);
searchForLectures(query);
}
}
}
searchable.xml中的常量字符串问题,与此问题的答案相同
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.