11

I'm trying to implement a PreferenceActivity in my app, following the accepted answer in this question

I get the above 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>

The activity launching code

@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);
    }
Community
  • 1
  • 1
PrashanD
  • 2,643
  • 4
  • 28
  • 58
  • 1
    Just change `com.iphonik.chameleon.AppPreferenceActivity` to `com.iphonik.AppPreferenceActivity` – M D May 18 '16 at 07:49

10 Answers10

8

declare your activity like this:

<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>

and use it:

Intent i = new Intent("com.iphonik.chameleon.AppPreferenceActivity");
Akbar
  • 430
  • 4
  • 18
0

From your manifest

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

remove com.iphonik.chameleon this

and looks like

<activity android:name=".AppPreferenceActivity"
                android:label="Preferences">
            </activity>
Bala Raja
  • 627
  • 6
  • 20
0

Change this lines

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

to

<activity android:name="com.iphonik.AppPreferenceActivity"
            android:label="Preferences">
        </activity>

in Manifest

Vishwesh Jainkuniya
  • 2,821
  • 3
  • 18
  • 35
  • It's not the manifest, but the activity launching code. It should change to intent.setClassName(this, "com.iphonik.chameleon.AppPreferenceActivity"); – PrashanD May 18 '16 at 07:55
0

Change

<activity android:name="com.iphonik.chameleon.AppPreferenceActivity" 
        android:label="Preferences">

to

<activity android:name="com.iphonik.AppPreferenceActivity"
        android:label="Preferences">
Naman
  • 27,789
  • 26
  • 218
  • 353
0

you must checked that if this path is excist in your class path. com.iphonik.chameleon.AppPreferenceActivity.

Saman Salehi
  • 1,004
  • 1
  • 12
  • 19
0

Change this

<activity android:name="com.iphonik.chameleon.AppPreferenceActivity"
        android:label="Preferences">

to

<activity android:name=".AppPreferenceActivity"
        android:label="Preferences">
0

Use below code

Manifest.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=".AppPreferenceActivity"
            android:label="Preferences">
        </activity>
    </application>

</manifest>

The activity launching code

@Override
    public boolean onOptionsItemSelected(MenuItem item){
        switch(item.getItemId()) {
            case R.id.preferences:
                Intent intent = new Intent(currentActivityName.this, AppPreferenceActivity.class);
                startActivity(intent);
                return true;
        }
        return super.onOptionsItemSelected(item);
    }
Vishwesh Jainkuniya
  • 2,821
  • 3
  • 18
  • 35
0

use correct package name and activity name should be start with dot (.)

example:

<manifest package="your.package.name">
  <application>
    <activity android:name=".ActivityName"/>
    //if you have sub packages
    <activity android:name=".subPackage.ActivityName"/>
  </application>
</manifest>
Gurwinder Singh
  • 109
  • 1
  • 3
0

I know this is a very old question but I found a solution. In my case it was going wrong because of activity mismatch. I imported an activity but it didn't match with the one in AndroidManifest.xml. I created two activities with same name ( name : LikesActivity ) but in two different places ( second one is inside a folder 'Likes'). I was importing an activity as "import your_package_name.LikesActivity". See below for clearance.

<activity android:name=".Home.HomeActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>

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

    <activity android:name=".Likes.LikesActivity" /> // See this line

See my import statement

import your_package_name.LikesActivity; 
.............
.............
Intent intent4 = new Intent(context, LikesActivity.class);
context.startActivity(intent4);

I changed my import statement to "import your_package_name.Likes.LikesActivity". What I did? I have injected "Likes" folder in b/w. Now it matched with the AndroidManifest.xml one.

Gunjan
  • 21
  • 2
-1

Removing the app from your phone and reinstalling it helped.

sapeg
  • 109
  • 7