1

Possible Duplicate:
How to open or simulate a click on a android Preference, which was created with XML, from code programatically?

Is it possible to use an Intent to open a Preference in a PreferenceActivity? For example, I'm using an OnPreferenceChangeListener to validate settings in an application, and rather than simply displaying an error message, I'd like to send the user back to the editing screen when an invalid value is entered.

Can an Intent open the editing screen? If not, is there another solution?

EDIT

Just to clarify, I'm not trying to access the Android device settings. I'm using a PreferenceActivity to display a custom set of preferences and want to create an Intent that allows the user to modify a specific preference. From the user's perspective, they would:

  1. Click on the preference
  2. Enter a value
  3. If the value is invalid, a message is displayed
    1. The user clicks "Ok"
    2. The app returns to the point where the user can enter a value (returns to step 2)
  4. If the value is valid, it is saved

When the user clicks ok, the app would immediately return to the point where a value can be entered, and does not require the user to click on the preference again.

Community
  • 1
  • 1
derekerdmann
  • 17,696
  • 11
  • 76
  • 110
  • What `editing screen` are you referring to? Do you mean the Android settings Activity? – Phil Aug 02 '11 at 19:35

1 Answers1

0

I'm assuming you are referring to the Android Settings. You can create a new Intent, passing in "android.settings.SETTINGS":

  startActivity(new Intent("android.settings.SETTINGS"));

Edit:

Now that I understand that you are using a PreferenceActivity, you should be able to override the onNewIntent(...) method to handle custom Intents (you can unpack the intent to see what the target preference is). From here, you can programmatically open the correct preference.

Phil
  • 35,852
  • 23
  • 123
  • 164
  • No, I'm referring to a custom set of preferences defined in a PreferencesActivity. The editing screen appears when you select a preference in the list. I want to go to a specific preference, not the entire PreferencesActivity. – derekerdmann Aug 02 '11 at 19:41
  • This link may help. It entails adding an intent filter to your manifest so you can use a new intent to open it: http://stackoverflow.com/questions/4681360/starting-custom-preferenceactivity-inside-another-preferenceactivity – Phil Aug 02 '11 at 19:44
  • 1
    As far as I know you cannot open a specific preference, only the "Preference Activity" – Jack Aug 02 '11 at 19:47
  • @Phil - The sticking point is where I "programmatically open the correct preference." That's really the core issue here; is there a way to do that? – derekerdmann Aug 02 '11 at 20:15
  • 1
    @derekerdmann, this question may be a duplicate of this: http://stackoverflow.com/questions/4805896/how-to-open-or-simulate-a-click-on-a-android-preference-which-was-created-with-x (or you may just find the link useful) – Phil Aug 02 '11 at 20:26
  • @Phil - Thanks, that's exactly what I was looking for. Voting to close as a duplicate. – derekerdmann Aug 03 '11 at 11:44