我试图编写一个自定义的Android同步适配器,我遵循了这个例子。使用上述示例中的以下代码片段后,我成功地在常规设置中显示了一个条目(帐户设置)。
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory android:title="General Settings" />
<PreferenceScreen android:key="account_settings"
android:title="Account Settings" android:summary="Sync frequency, notifications, etc.">
<intent android:action="fm.last.android.activity.Preferences.ACCOUNT_SETUP"
android:targetPackage="fm.last.android"
android:targetClass="fm.last.android.activity.Preferences" />
</PreferenceScreen>
</PreferenceCategory>
</PreferenceScreen>
在“常规设置”中,我的代码生成了一个条目(账户设置):
当我点击账户设置时,我会收到以下错误消息,并且设备会不必要地重新启动。
ERROR/AndroidRuntime(30057): android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
我知道这个错误可以通过代码解决。由于“账户设置”首选项是基于XML的代码,所以我无法解决这个错误。
有人能帮忙解决这个问题吗?
我们如何通过代码控制这些偏好设置?