的onCreate()或onNewIntent()时,搜索键pressed没有被解雇 [英] onCreate() or onNewIntent() not fired when search button pressed
问题描述
我想在我的应用程序,这是目前非常基本实现搜索功能。当我preSS对我的Nexus搜索按钮,搜索意图似乎不火,因为既不的onCreate(),也不onNewIntent()被调用。我已经基本复制了整个例如,你可以找到关于 Android开发的,但它仍然没有工作。感谢您的帮助。
RES / searchable.xml
<?XML版本=1.0编码=UTF-8&GT?;
<搜索的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:标签=你好
机器人:提示=搜索讲座>
< /搜索>
AndroidManifest.xml中
<?XML版本=1.0编码=UTF-8&GT?;
<清单的xmlns:机器人=http://schemas.android.com/apk/res/android
包=com.openday.lectures
安卓版code =1
机器人:=的versionName1.0>
<采用-SDK安卓的minSdkVersion =7/> <应用机器人:图标=@绘制/图标机器人:标签=@字符串/ APP_NAME>
<活动机器人:名字=。LecturesListActivity
机器人:标签=@字符串/ APP_NAME
机器人:launchMode =singleTop>
&所述;意图滤光器>
<作用机器人:名字=android.intent.action.MAIN/>
<类机器人:名字=android.intent.category.LAUNCHER/>
&所述; /意图滤光器>
&所述;意图滤光器>
<作用机器人:名字=android.intent.action.SEARCH/>
&所述; /意图滤光器>
<元数据机器人:名字=android.app.searchable
机器人:资源=@ XML /搜索/>
< /活性GT;
<活动机器人:名字=。SingleLectureActivity
机器人:标签=百家>
< /活性GT;
< /用途><使用许可权的android:NAME =android.permission.INTERNET对/>
<使用许可权的android:NAME =android.permission.WRITE_EXTERNAL_STORAGE/>
< /清单>
LecturesListActivity.java(缩短)
公共类LecturesListActivity扩展ListActivity { 私人字符串categoryDisplayed;
私人字符串facultyDisplayed;
私人列表<演讲及GT;讲座; / **当第一次创建活动调用。 * /
@覆盖
公共无效的onCreate(捆绑savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.main);
loadLectures();
displayFaculties();
} @覆盖
保护无效onNewIntent(意向意图){
setIntent(意向);
handleIntent(意向);
} 私人无效handleIntent(意向意图){
如果(Intent.ACTION_SEARCH.equals(intent.getAction())){
查询字符串= intent.getStringExtra(SearchManager.QUERY);
searchForLectures(查询);
}
}
}
的问题与searchable.xml字符串常量,相同的答案的这个问题
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. I have basically copied the whole example you can find on Android developers, but it is still not working. Thanks for your help
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
<?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)
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);
}
}
}
Problem with constant string in searchable.xml, same answer as this question
这篇关于的onCreate()或onNewIntent()时,搜索键pressed没有被解雇的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!