Activitynotfoundexception When Different Package's Targetclass In Preferencescreen
Solution 1:
I just ran into the same problem when trying to use a custom preference screen from a library project for the AccountManager account settings. No matter how I tried to tweak the targetPackage and targetClass attributes, it would throw an exception (except, since it's an account, it crashes the phone).
I think we'll just have to assume this is an Android limitation. It's clumsy, but all you really need to do is declare a wrapper class for the activity within your application's namespace:
publicclassMyPreferencesextendsActualPreferences {
}
Declare it in your AndroidManifest.xml
<activityandroid:name=".MyPreferences"/>
Then you can specify the class in your intent
<intentandroid:targetPackage="com.my.package"android:targetClass="com.my.package.MyPreferences" />
By the way, the syntax is extremely fussy, at least for account preferences. All these variations fail:
<!-- fails --><intentandroid:targetClass="com.my.package.MyPreferences" /><!-- fails --><intentandroid:targetClass="MyPreferences"android:targetPackage="com.my.package"/><!-- fails --><intentandroid:targetClass=".MyPreferences"android:targetPackage="com.my.package"/><!-- fails --><intentandroid:targetClass="settings.MyPreferences"android:targetPackage="com.my.package"/><!-- fails --><intentandroid:targetClass=".settings.MyPreferences"android:targetPackage="com.my.package"/><!-- fails --><intentandroid:targetClass="com.my.other.package.MyPreferences"android:targetPackage="com.my.package"/>
The critical factor is apparently that the android:targetPackage
attribute matches the application package. If you want, you can put the activity in a sub-package. This works:
<intentandroid:targetPackage="com.my.package"android:targetClass="com.my.package.settings.MyPreferences" />
Solution 2:
as already said its not working with libraries. Do it programatically, something like this:
preference_my_pref.setOnPreferenceClickListener(newOnPreferenceClickListener() {
publicbooleanonPreferenceClick(Preference preference) {
Intentintent=newIntent(MyActivity.this, ActivityToStart.class);
startActivity(intent);
returntrue;
}
});
Post a Comment for "Activitynotfoundexception When Different Package's Targetclass In Preferencescreen"