BooleanPreference extends Preference<Boolean> { public void toggle() { final Boolean value = get(); if (Boolean.TRUE.equals(value)) { set(Boolean.FALSE); } else if (Boolean.FALSE.equals(value)) { set(Boolean.TRUE); } } BooleanPreference(final String name, final String key,
            @Nullable final Boolean defaultValue); @Override boolean exists(); @Nullable @Override Boolean get(); void toggle();  }
@Test public void testToggle() throws Exception { mNullPref.toggle(); assertNull(mNullPref.get()); mFalsePref.toggle(); assertTrue(mFalsePref.get()); mFalsePref.toggle(); assertFalse(mFalsePref.get()); mTruePref.toggle(); assertFalse(mTruePref.get()); mTruePref.toggle(); assertTrue(mTruePref.get()); }