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

Commit

Permalink
Adding try/catch to SnapshotNotificationActivity to fix crash
Browse files Browse the repository at this point in the history
  • Loading branch information
Langston Smith authored and langsmith committed Oct 2, 2019
1 parent 3dadd83 commit 95e2d0d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.graphics.Bitmap;
import android.os.Build;
import android.os.Bundle;
import android.widget.Toast;

import com.mapbox.mapboxandroiddemo.MainActivity;
import com.mapbox.mapboxandroiddemo.R;
Expand All @@ -24,6 +25,7 @@
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.NotificationCompat;
import timber.log.Timber;

import static android.app.PendingIntent.getActivity;

Expand Down Expand Up @@ -102,12 +104,18 @@ public void onStyleLoaded(@NonNull Style style) {
mapSnapshotter.setSize(width, height);
mapSnapshotter.setRegion(latLngBounds);
}
mapSnapshotter.start(new MapSnapshotter.SnapshotReadyCallback() {
@Override
public void onSnapshotReady(MapSnapshot snapshot) {
createNotification(snapshot.getBitmap());
}
});
try {
mapSnapshotter.start(new MapSnapshotter.SnapshotReadyCallback() {
@Override
public void onSnapshotReady(MapSnapshot snapshot) {
createNotification(snapshot.getBitmap());
}
});
} catch (IllegalStateException exception) {
Timber.d(exception);
Toast.makeText(SnapshotNotificationActivity.this,
R.string.snapshotter_was_already_started, Toast.LENGTH_SHORT).show();
}
}
});
}
Expand Down
1 change: 1 addition & 0 deletions MapboxAndroidDemo/src/main/res/values/activity_strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
<!--Tap on map instruction for toast-->
<string name="tap_on_map_instruction">Tap anywhere on the map</string>
<string name="tap_on_map_for_notification">Tap on map to get a notification with map image</string>
<string name="snapshotter_was_already_started">Snapshotter was already started</string>

<string name="san_francisco">San Francisco</string>
<string name="los_angeles">Los Angeles</string>
Expand Down

0 comments on commit 95e2d0d

Please sign in to comment.