J'essaie d'implémenter PreferenceActivity dans mon application, en suivant la réponse acceptée dans cette question
Je reçois l'exception ci-dessus
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>
Le code de lancement de l'activité
@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);
}
déclarez votre activité comme ceci:
<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>
et l'utiliser:
Intent i = new Intent("com.iphonik.chameleon.AppPreferenceActivity");
De votre manifeste
<activity Android:name="com.iphonik.chameleon.AppPreferenceActivity"
Android:label="Preferences">
</activity>
enlever com.iphonik.chameleon
ceci
et ressemble à
<activity Android:name=".AppPreferenceActivity"
Android:label="Preferences">
</activity>
Changer ces lignes
<activity Android:name="com.iphonik.chameleon.AppPreferenceActivity"
Android:label="Preferences">
</activity>
à
<activity Android:name="com.iphonik.AppPreferenceActivity"
Android:label="Preferences">
</activity>
dans le manifeste
Changement
<activity Android:name="com.iphonik.chameleon.AppPreferenceActivity"
Android:label="Preferences">
à
<activity Android:name="com.iphonik.AppPreferenceActivity"
Android:label="Preferences">
utiliser le nom correct du package et le nom de l'activité doivent commencer par un point (.)
exemple:
<manifest package="your.package.name">
<application>
<activity Android:name=".ActivityName"/>
//if you have sub packages
<activity Android:name=".subPackage.ActivityName"/>
</application>
</manifest>
vous devez vérifier que si ce chemin existe dans votre chemin de classe. com.iphonik.chameleon.App PreferenceActivity.
Change ça
<activity Android:name="com.iphonik.chameleon.AppPreferenceActivity"
Android:label="Preferences">
à
<activity Android:name=".AppPreferenceActivity"
Android:label="Preferences">
Utilisez le code ci-dessous
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>
Le code de lancement de l'activité
@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);
}