从preferences.xml开始活动,并得到结果onActivityResult [英] Start Activity from preferences.xml and get the result in onActivityResult
问题描述
这是一个补充这个问题。
我可以启动活动,但我也需要能够得到的结果。我该怎么做呢?
I can launch the Activity but I also need to be able to get the result. How do I do it?
我想对我的preferencesActivity覆盖onActivityResult无济于事。
I tried overriding onActivityResult on my PreferencesActivity to no avail.
我缺少在preferences.xml一些额外的属性?
Am I missing some extra properties in the preferences.xml?
推荐答案
这是我所知道的是听的preference点击并明确推出意图的干净的解决方案。这样 onActivityResult
将被称为像往常一样。
The cleanest solution that I know of is to listen to the click on the preference and launch the intent explicitly. This way onActivityResult
will be called as usual.
假设你的intent- preference在XML定义就可以把监听器像这样(其中 1234
是一个请求$ C $下 onActivityResult
):
Assuming that your intent-preference is defined in XML you can attach a listener to it like this (where 1234
is a request code for onActivityResult
):
Preference pref = (Preference) findPreference("prefKey");
pref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
startActivityForResult(preference.getIntent(), 1234);
return true;
}
});
这篇关于从preferences.xml开始活动,并得到结果onActivityResult的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!