diff --git a/src/androidTest/res/raw/gpx_timezone.gpx b/src/androidTest/res/raw/gpx_timezone.gpx
index 82bcef0413..23d7548435 100644
--- a/src/androidTest/res/raw/gpx_timezone.gpx
+++ b/src/androidTest/res/raw/gpx_timezone.gpx
@@ -31,8 +31,6 @@ xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/
0
0
0.0
-null
-null
diff --git a/src/main/java/de/dennisguse/opentracks/io/file/exporter/GPXTrackExporter.java b/src/main/java/de/dennisguse/opentracks/io/file/exporter/GPXTrackExporter.java
index a2354f8614..a4de84eab6 100644
--- a/src/main/java/de/dennisguse/opentracks/io/file/exporter/GPXTrackExporter.java
+++ b/src/main/java/de/dennisguse/opentracks/io/file/exporter/GPXTrackExporter.java
@@ -279,8 +279,12 @@ public void writeBeginTrack(Track track) {
printWriter.println("" + trackStatistics.getMovingTime().getSeconds() + "");
printWriter.println("" + trackStatistics.getStoppedTime().getSeconds() + "");
printWriter.println("" + trackStatistics.getMaxSpeed().toMPS() + "");
- printWriter.println("" + trackStatistics.getTotalAltitudeGain() + "");
- printWriter.println("" + trackStatistics.getTotalAltitudeLoss() + "");
+ if (trackStatistics.hasTotalAltitudeGain()) {
+ printWriter.println("" + trackStatistics.getTotalAltitudeGain() + "");
+ }
+ if (trackStatistics.hasTotalAltitudeLoss()) {
+ printWriter.println("" + trackStatistics.getTotalAltitudeLoss() + "");
+ }
printWriter.println("");
printWriter.println("");