Hi,
I've been playing around a bit with Preferences and trying to
understand how addPreferencesFromIntent works, but I haven't really
got it to work. Are there any examples of how to use this at all?
I have one (or more) application providing preferences which I want to
display in another (host) application, but I don't want to hard-code
the dependency to the PreferenceActivity providing the preferences. So
this is roughly what I did:
Provider application:
* Added a PreferenceActivity foo.provider.PreferenceActivity coupled
to a preferences XML resource consisting of two checkbox preferences
(calling addPreferencesFromResource from onCreate)
* Added another PreferenceActivity
foo.provider.PreferenceProviderActivity with an intent-filter using a
custom action "foo.action.preference" and a meta-data section pointing
to a preference xml, consisting of a PreferenceScreen with a title and
summary and pointing to the above activity using <intent
android:action="android.intent.action.main"
android:targetPackage="foo.provider"
android:targetClass="foo.provider.PreferenceActivity". The onCreate
method is empty.
Host application:
* Added a PreferenceActivity calling addPreferencesFromIntent(new
Intent("foo.action.preference"))
The result is that I get a screen with only a title (coming from the
provider application) but no items. This kind of makes sense to me
since my hiearchy now only has one element, the root PreferenceScreen,
and I assume that element cannot have any <intent> since the root
PreferenceScreen is not an item in itself.
So I tried adding a root PreferenceScreen before calling
addPreferencesFromIntent, but that doesn't work at all. Now, my
provider preferences are not added at all!
So then I tried adding a second nested PreferenceScreen in the
provider's preference XML, and now it looks OK, I get the provider
item in my host application. However, when clicking on the item that
should launch foo.provider.PreferenceActivity, I get an exception
saying
android.util.AndroidRuntimeException: Calling startActivity() from
outside an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag.
Is this really what you want?
Also, this approach doesn't seem right if I were to add more than one
provider, right? What I want is to have one root PreferenceScreen
added by the host application, and to then populate this hierarchy
with single child PreferenceScreen elements from the providers. I
can't have the root element coming from one of the providers...
So what am I doing wrong here? Any help or examples would be greatly
appreciated!
BR
/Henrik
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---