如何创建使用返回结果的现有活动的自定义首选项?
Preference 类允许设置 Intent,以便在单击时激活另一个活动,但我无法找到使用此方法处理活动结果的方法。还有 DialogPreference,我可以在其中提供自定义视图,但我无法直接访问我想要使用的视图,只能访问一个活动。
进一步挖掘,看起来 RingtonePreference 使用 PreferenceManager 上的一些包内部方法来接收已启动的子活动的结果,但由于这些是包内部的,我无法执行相同的操作。
是否有其他方法可以通过返回结果的活动来处理自定义首选项(其中结果将保存为首选项的值)?
The Preference class allows for an Intent to be set, to have a preference activate another activity when clicked, but I'm unable to find a way to handle the result from an activity using this method. There's also the DialogPreference where I can provide a custom view, but I don't have direct access to the view I want to use, only an activity.
Digging a bit further, it looks like the RingtonePreference uses a few package internal methods on PreferenceManager to receive results from a started sub-activity, but as these are package internal I am unable to do the same.
Is there any other way of handling a custom preference with an activity that returns a result (where the result is to be saved as the value of the preference)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我还注意到 PreferenceActivity 不会返回 onActivityResult。话虽如此,您的子活动是否有原因无法直接保存首选项?如果您需要检查它的值,您可以在 PreferenceActivity 的 onResume 上检查它作为解决方法。
I have also noticed PreferenceActivity does not return onActivityResult. That being said, is there a reason your SubActivity couldn't save the preference directly? If you need to check the value of it, you could check it at onResume of your PreferenceActivity as a workaround..