无法启动可搜索的活动

时间:2013-02-19 10:50:25

标签: java android search android-activity

使用searchview显示内置搜索的代码。 请问有人告诉我它有什么问题吗? SearchableActivity在scr中创建 - >演示文稿,它使用名为search.xml的xml布局。我是android新手,无法找出我的代码有什么问题。当启动搜索视图键入一个单词并按下键盘上的“Go”时,调试器会打开一个ActivityThread.perfor ....并告诉我找不到源。

这是我的洞manifest.xml:

   <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="myTV.Android"
android:versionCode="4"
android:versionName="1.12" >

<uses-sdk
    android:minSdkVersion="11"
    android:targetSdkVersion="12" />

<uses-feature
    android:name="com.google.android.tv"
    android:required="true" />
<uses-feature
    android:name="android.hardware.touchscreen"
    android:required="false" />

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

<application
    android:icon="@drawable/mytv"
    android:label="@string/app_name"
    android:theme="@style/Theme.Transparent" >
    <activity android:name="myTV.Presentation.Main" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name="myTV.Presentation.Player" >
    </activity>
    <activity android:name="myTV.Presentation.VODCatalogGenre" >
    </activity>
    <activity android:name="myTV.Presentation.VODCatalog" >
    </activity>
    <activity android:name="myTV.Presentation.HomePage" >
    </activity>
    <activity android:name="myTV.Presentation.Programs" >
    </activity>
    <activity android:name="myTV.Presentation.Episodes" >
        <intent-filter>
            <action android:name="android.intent.action.SEARCH" />
        </intent-filter>
    </activity>
    <activity android:name="myTV.Presentation.ChannelsListing" >
    </activity>
    <activity android:name="myTV.Presentation.Packages" >
    </activity>
    <activity android:name="myTV.Presentation.SpecialOfferContent" >
    </activity>
    <activity android:name="myTV.Presentation.linkedpage" >
    </activity>
    <activity android:name="myTV.Presentation.howtolinkdevice" >
    </activity>
    <activity android:name="myTV.Presentation.OnlineRegister" >
    </activity>
    <activity android:name="myTV.Presentation.SpecialOffer" >
    </activity>
    <activity android:name="myTV.Presentation.MyVOD" >
    </activity>
    <activity android:name="myTV.Presentation.SearchEpisodes" >
    </activity>
    <activity android:name=".Countries" />
    <activity android:name=".Genres" />
    <activity android:name=".WeeklyRecap" />


    <meta-data
        android:name="android.app.default_searchable"
        android:value=".SearchableActivity" />
    <activity android:name=".SearchableActivity" > 
        <intent-filter>
            <action android:name="android.intent.action.SEARCH" />
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </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>
</application>

    import myTV.Android.R;
    import android.app.Activity;
    import android.app.SearchManager;
    import android.content.Context;
    import android.content.Intent;
    import android.os.Bundle;
    import android.widget.Toast;

    public class SearchableActivity extends Activity{

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.search);

    // Get the intent, verify the action and get the query
    Intent intent = getIntent();
    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
      String query = intent.getStringExtra(SearchManager.QUERY);
      doMySearch(query);
    }
}
public void doMySearch(String query){
    //new Request().Search(query);
    //new SearchEpisodes().Search(query);
    Context context = getApplicationContext();
    CharSequence text = query;
    int duration = Toast.LENGTH_LONG;

    Toast toast = Toast.makeText(context, text, duration);
    toast.show();
}


    }

这是我的searchable.xml:

    <searchable xmlns:android="http://schemas.android.com/apk/res/android"
        android:label="@string/app_name"
        android:hint="@string/SearchHint" >
</searchable>

2 个答案:

答案 0 :(得分:0)

我认为,您的活动在应用程序之外是不可见的。

尝试android:exported="true"

答案 1 :(得分:0)

尝试在<intent-filter>中添加以下内容。

<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />