My application has a setting menu which is actually a PreferenceActivity.
When it’s created, if a boolean value is not set I want to go to the DialogPreference which sets that.
I tried doing it with an intent but the application force closed with this error msg:
E/AndroidRuntime( 239):
android.content.ActivityNotFoundException:
Unable to find explicit activity class
{com.xxxx/com.xxxx.xxxxPreference};
have you declared this activity in
your AndroidManifest.xml?
How should I do this? It’s ok to add that DialogPreference to the manifest?
A
DialogPreferenceisn’t anActivityin its own right. It’s just aPreferencewhich displays aDialogwhen clicked.The problem is that there’s no obvious way programmatically click a
Preference. However, since you’re usingDialogPreferenceyou’ve already got you own subclass of it. So we can solve our problem by adding the following method to your subclass ofDialogPreference:Then in the
onCreate()of yourPreferencesActivityyou’ll have something like this to load the preferences from your XML file:After that you can put some code like this:
This is a bit of hack, as exposing
protectedmethods isn’t ideal, but it does work.Another option would be to replace the
Dialogwith aPrefenceActivitywhich contained all the options you wish to maintain and then you could launch it via anIntent, but I’m assuming there’s a good reason that you want your own customDialogwith a specific layout. If you do want a secondPreferenceActivityyou can add it to your preferences XML file as follows: