我正在尝试创建我的第一个Android应用程序,并在添加SEARCH功能的过程中.我已经按照Android Developer文档添加了"搜索"对话框和小部件.不幸的是,每当我执行搜索时,都会调用搜索活动的"onCreate"和"onNewIntent".也就是说,通过在操作栏搜索框中键入内容并按Enter键,搜索称为TWICE.我被卡住了.是否应该从Searchable活动返回一些全球标志,通知应用程序搜索已完成?是否同时调用了搜索对话框和小部件?
我在这个网站上和网上搜索了以前的帖子都无济于事.感谢您的任何帮助.
AndroidManifest.xml中
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.shop"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<service android:name="com.shop.RestIntentService" />
<activity
android:name="com.shop.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.shop.CatalogActivity"
android:label="@string/app_name" >
</activity>
<activity
android:name="com.shop.SearchableActivity"
android:launchMode="singleTop" >
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<!--
<intent-filter>
<action android:name="android.intent.action.VIEW" />
</intent-filter>
-->
<meta-data
android:name="android.app.searchable"
android:resource="@xml/searchable" />
</activity>
<meta-data
android:name="android.app.default_searchable"
android:value="com.shop.SearchableActivity" />
</application>
</manifest>
Run Code Online (Sandbox Code Playgroud)
SearchableActivity.java
public class SearchableActivity extends ListActivity …Run Code Online (Sandbox Code Playgroud)