Skip to content
This repository was archived by the owner on Oct 7, 2024. It is now read-only.

Commit 95e2d0d

Browse files
Langston Smithlangsmith
authored andcommitted
Adding try/catch to SnapshotNotificationActivity to fix crash
1 parent 3dadd83 commit 95e2d0d

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

MapboxAndroidDemo/src/main/java/com/mapbox/mapboxandroiddemo/examples/snapshot/SnapshotNotificationActivity.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import android.graphics.Bitmap;
99
import android.os.Build;
1010
import android.os.Bundle;
11+
import android.widget.Toast;
1112

1213
import com.mapbox.mapboxandroiddemo.MainActivity;
1314
import com.mapbox.mapboxandroiddemo.R;
@@ -24,6 +25,7 @@
2425
import androidx.annotation.NonNull;
2526
import androidx.appcompat.app.AppCompatActivity;
2627
import androidx.core.app.NotificationCompat;
28+
import timber.log.Timber;
2729

2830
import static android.app.PendingIntent.getActivity;
2931

@@ -102,12 +104,18 @@ public void onStyleLoaded(@NonNull Style style) {
102104
mapSnapshotter.setSize(width, height);
103105
mapSnapshotter.setRegion(latLngBounds);
104106
}
105-
mapSnapshotter.start(new MapSnapshotter.SnapshotReadyCallback() {
106-
@Override
107-
public void onSnapshotReady(MapSnapshot snapshot) {
108-
createNotification(snapshot.getBitmap());
109-
}
110-
});
107+
try {
108+
mapSnapshotter.start(new MapSnapshotter.SnapshotReadyCallback() {
109+
@Override
110+
public void onSnapshotReady(MapSnapshot snapshot) {
111+
createNotification(snapshot.getBitmap());
112+
}
113+
});
114+
} catch (IllegalStateException exception) {
115+
Timber.d(exception);
116+
Toast.makeText(SnapshotNotificationActivity.this,
117+
R.string.snapshotter_was_already_started, Toast.LENGTH_SHORT).show();
118+
}
111119
}
112120
});
113121
}

MapboxAndroidDemo/src/main/res/values/activity_strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@
121121
<!--Tap on map instruction for toast-->
122122
<string name="tap_on_map_instruction">Tap anywhere on the map</string>
123123
<string name="tap_on_map_for_notification">Tap on map to get a notification with map image</string>
124+
<string name="snapshotter_was_already_started">Snapshotter was already started</string>
124125

125126
<string name="san_francisco">San Francisco</string>
126127
<string name="los_angeles">Los Angeles</string>

0 commit comments

Comments
 (0)