我正在尝试按照this question中可接受的答案在我的应用程序中实现PreferenceActivity

我得到上述异常(exception)

android.content.ActivityNotFoundException: Unable to find explicit activity class {com.iphonik.chameleon/com.iphonik.AppPreferenceActivity}; have you declared this activity in your AndroidManifest.xml?

AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.iphonik.chameleon">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.GET_TASKS" />
    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@android:style/Theme.NoTitleBar">
        <activity android:name=".MainMenu">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".Movies" />
        <activity android:name=".SettingsActivity" />
        <activity android:name=".InfoActivity" />

        <receiver
            android:name=".AppBroadcastReciever"
            android:enabled="true"
            android:exported="true"
            android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </receiver>

        <activity android:name=".Info2Activity" />
        <activity android:name=".ItemDetailActivity" />
        <activity android:name=".TVActivity" />
        <activity android:name="com.iphonik.chameleon.AppPreferenceActivity"
            android:label="Preferences">
        </activity>
    </application>

</manifest>

Activity 启动代码
@Override
    public boolean onOptionsItemSelected(MenuItem item){
        switch(item.getItemId()) {
            case R.id.preferences:
                Intent intent = new Intent();
                intent.setClassName(this, "com.iphonik.AppPreferenceActivity");
                startActivity(intent);
                return true;
        }
        return super.onOptionsItemSelected(item);
    }

最佳答案

像这样声明您的 Activity :

<activity
        android:name=".AppPreferenceActivity"
        android:label="Preferences" >
        <intent-filter>
            <action android:name="com.iphonik.chameleon.AppPreferenceActivity" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

并使用它:
Intent i = new Intent("com.iphonik.chameleon.AppPreferenceActivity");

关于android - 找不到明确的 Activity 类别。您是否在AndroidManifest.xml中声明了此 Activity ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37293314/

10-11 22:26