private boolean createSettingsBackupInternal(final Folder backupDir, final Boolean fullBackup) {
        final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(CgeoApplication.getInstance().getBaseContext());
        final Map<String, ?> keys = prefs.getAll();
        final HashSet<String> ignoreKeys = new HashSet<>();

        // if a backup without account data is requested add all account related preference keys to the ignore set
        if (!fullBackup) {
            ignoreKeys.addAll(Settings.getSensitivePreferenceKeys(activityContext));
        }

        final Uri backupFile = ContentStorage.get().create(backupDir, SETTINGS_FILENAME);
        Writer writer = null;
        boolean success = true;
        try {

            final OutputStream os = ContentStorage.get().openForWrite(backupFile);
            if (os == null) {
                throw new IOException("Could not open backup file uri for writing:" + backupFile);
            }
            writer = new OutputStreamWriter(os, StandardCharsets.UTF_8);

            final XmlSerializer xmlSerializer = Xml.newSerializer();
            xmlSerializer.setOutput(writer);
            xmlSerializer.startDocument("UTF-8", true);

            xmlSerializer.startTag(null, TAG_MAP);
            for (Map.Entry<String, ?> entry : keys.entrySet()) {
                final Object value = entry.getValue();
                final String key = entry.getKey();
                if (!ignoreKeys.contains(key)) {
                    final SettingsUtils.SettingsType type = SettingsUtils.getType(value);
                    if (type == TYPE_STRING) {
                        xmlSerializer.startTag(null, type.getId());
                        xmlSerializer.attribute(null, ATTRIBUTE_NAME, key);
                        xmlSerializer.text(value.toString());
                        xmlSerializer.endTag(null, type.getId());
                    } else if (type != TYPE_UNKNOWN) {
                        xmlSerializer.startTag(null, type.getId());
                        xmlSerializer.attribute(null, ATTRIBUTE_NAME, key);
                        xmlSerializer.attribute(null, ATTRIBUTE_VALUE, value.toString());
                        xmlSerializer.endTag(null, type.getId());
                    }
                }
            }
            xmlSerializer.endTag(null, TAG_MAP);

            xmlSerializer.endDocument();
            xmlSerializer.flush();
        } catch (IllegalArgumentException | IllegalStateException | IOException e) {
            success = false;
            final String error = e.getMessage();
            if (null != error) {
                Log.e("error writing settings file: " + error);
            }
        }
        IOUtils.closeQuietly(writer);
        return success;
    }
Private methods containing the real backup process
main/src/main/java/cgeo/geocaching/utils/BackupUtils.java