不是您问题的真正答案,但非常相关。也许有人会发现它很有用。对于较新的 API (>11),您有一个首选项标头文件,您可以为其中一个标头定义自定义意图。我试图向其中一个标题添加自定义 Extra,我找到的解决方案如下所示:
在您的preference-headers.xml 中:
<header
android:fragment="com.mypackage.MyPreference$Prefs1Fragment"
android:title="Intent"
android:summary="Launches an Intent.">
</header>
在您的“MyPreference”类(扩展 PreferenceActivity)中,您有:
public static class Prefs1Fragment extends PreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = new Intent(getActivity(), MyTargetActivity.class);
// set the desired extras, flags etc to the intent
intent.putExtra("customExtra", "Something that I used to know");
// starting our target activity
startActivity(intent);
// ending the current activity, which is just a redirector to our end goal
getActivity().finish();
}
}