我在我的应用程序中使用 parse.com 推送通知。我在应用程序设置中添加了一个“禁用通知”选项,如下所示:
<PreferenceCategory android:title="Obvestila" >
<CheckBoxPreference
android:defaultValue="true"
android:key="prefNotification"
android:summary="Za obvestila je potrebna internetna povezava"
android:title="Prejemal obvestila" />
</PreferenceCategory>
然后将此方法添加到MainActivity:
public void getSettingsPrefs(){
SharedPreferences settingsPrefs = PreferenceManager.getDefaultSharedPreferences(this);
notification = settingsPrefs.getBoolean("prefNotification", true);
if (notification == false)
{
PushService.setDefaultPushCallback(this, null);
}
else
{
PushService.setDefaultPushCallback(this, MainActivity.class);
}
}
现在的问题是这只是部分有效。在设置中选中或取消选中该框后,我需要完全重新打开 MainActivity,以便在 onCreate 中执行 getSettingsPrefs()。每次选中复选框时,如何使 IF 语句执行?