From 686ee7ed86be3943bef1f117d194e742354ef08c Mon Sep 17 00:00:00 2001 From: Tom Hennen Date: Sat, 2 May 2015 09:27:13 -0400 Subject: [PATCH] fixes a null pointer exception that can sometimes occur when the PlaybackWidgetService is shutdown --- .../service/PlayerWidgetService.java | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/de/danoeh/antennapod/service/PlayerWidgetService.java b/app/src/main/java/de/danoeh/antennapod/service/PlayerWidgetService.java index 1d9e8e412..0d00823d3 100644 --- a/app/src/main/java/de/danoeh/antennapod/service/PlayerWidgetService.java +++ b/app/src/main/java/de/danoeh/antennapod/service/PlayerWidgetService.java @@ -52,19 +52,20 @@ public class PlayerWidgetService extends Service { public void onDestroy() { super.onDestroy(); Log.d(TAG, "Service is about to be destroyed"); - - Playable playable = playbackService.getPlayable(); - if(playable != null && playable instanceof FeedMedia) { - FeedMedia media = (FeedMedia) playable; - if(media.hasAlmostEnded()) { - Log.d(TAG, "smart mark as read"); - FeedItem item = media.getItem(); - DBWriter.markItemRead(this, item, true, false); - DBWriter.removeQueueItem(this, item, false); - DBWriter.addItemToPlaybackHistory(this, media); - if (UserPreferences.isAutoDelete()) { - Log.d(TAG, "Delete " + media.toString()); - DBWriter.deleteFeedMediaOfItem(this, media.getId()); + if (playbackService != null) { + Playable playable = playbackService.getPlayable(); + if (playable != null && playable instanceof FeedMedia) { + FeedMedia media = (FeedMedia) playable; + if (media.hasAlmostEnded()) { + Log.d(TAG, "smart mark as read"); + FeedItem item = media.getItem(); + DBWriter.markItemRead(this, item, true, false); + DBWriter.removeQueueItem(this, item, false); + DBWriter.addItemToPlaybackHistory(this, media); + if (UserPreferences.isAutoDelete()) { + Log.d(TAG, "Delete " + media.toString()); + DBWriter.deleteFeedMediaOfItem(this, media.getId()); + } } } }