The application's default package is "example.app".
and the target activity's package is "example.app.abc".
Calling startActivity() for "example.app.abc.TheActivity" in java code just works,
but specifying it on preference.xml doesn't work:
<PreferenceScreen android:key="key"
android:title="@string/title"
>
<intent android:action="android.intent.action.MAIN"
android:targetPackage="example.app.abc"
android:targetClass="TheActivity"
/>
</PreferenceScreen>
I tried android:targetClass="example.app.abc.TheActivity" but it doesn't work too.
Is it impossible to start an activity of non-default package, in preference?
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:
Declare it in your AndroidManifest.xml
Then you can specify the class in your intent
By the way, the syntax is extremely fussy, at least for account preferences. All these variations fail:
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:as already said its not working with libraries. Do it programatically, something like this: