6

I have a PreferenceScreen that is defined in XML that serves all the preferences for my application. This PreferenceScreen also has a child PreferenceScreen nested within it. My implementing class is called PreferencesActivity. I know I can open the main Preferences window via startActivity(new Intent(this, PreferencesActivity.class)); but how do I go about opening the child PreferenceScreen via an Intent?

Mike
  • 81
  • 1
  • 4

2 Answers2

4

i researched a while on this topic for my project Theft Aware (http://www.theftaware.com) (a little bit advertisement... :-) and i found the solution:

PreferenceScreen screen = getPreferenceScreen(); // gets the main preference screen     
screen.onItemClick(null, null, INDEX , 0); // click on the item

where INDEX is the position of the item you want to open on the screen

richsage
  • 26,912
  • 8
  • 58
  • 65
Reinhard
  • 41
  • 2
  • Thank you very much!!! I am wondering if this can be adapted to make the positioning of the items agnostic. – Mike Jul 01 '10 at 11:44
  • 1
    I've implemented the method by Reinhard to solve it more generally, see the link in my answer to my question! – Markus Feb 02 '11 at 11:51
3

see this question for a more general solution based on Reinhard's idea, finally!

Community
  • 1
  • 1
Markus
  • 5,667
  • 4
  • 48
  • 64
  • Works, but if you're using PreferenceCategories be sure to read down for the code by deepak patel and use that, otherwise 'getOrder' will not work – Carlos P Mar 18 '15 at 18:11