开发者

Use Intent to open Android preference for editing [duplicate]

This question already has answers here: Closed 11 years ago.

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 pref开发者_JAVA百科erences 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜