@Override
    protected Uri doInBackgroundInternal(final String[] geocodes) {
        final List<String> allGeocodes = new ArrayList<>(Arrays.asList(geocodes));

        setMessage(CgeoApplication.getInstance().getResources().getQuantityString(R.plurals.cache_counts, allGeocodes.size(), allGeocodes.size()));

        final Uri uri = ContentStorage.get().create(PersistableFolder.GPX, filename);
        if (uri == null) {
            return null;
        }

        BufferedWriter writer = null;
        try (OutputStream os = ContentStorage.get().openForWrite(uri)) {
            if (os == null) {
                return null;
            }

            writer = new BufferedWriter(new OutputStreamWriter(os, StandardCharsets.UTF_8));
            new GpxSerializer().writeGPX(allGeocodes, writer, this::publishProgress);
        } catch (final IOException e) {
            Log.e("GpxExport.ExportTask export", e);
            // delete partial GPX file on error
            ContentStorage.get().delete(uri);

            return null;
        } finally {
            IOUtils.closeQuietly(writer);
        }

        return uri;
    }
Instantiates and configures the task for exporting gpx files.

@param activity optional: Show a progress bar and toasts
main/src/main/java/cgeo/geocaching/export/GpxExportTask.java