diff options
author | ByteHamster <info@bytehamster.com> | 2020-04-02 19:40:24 +0200 |
---|---|---|
committer | ByteHamster <info@bytehamster.com> | 2020-04-02 19:40:24 +0200 |
commit | 8c879ede9b6cedb64e37a58d0d9f50c35951141a (patch) | |
tree | 11692869677af9e56754a2ce40a1ba07ff9f200a /core | |
parent | 5e344baf4b0689db9addcfcb07ca14ba6f51c1a0 (diff) | |
download | AntennaPod-8c879ede9b6cedb64e37a58d0d9f50c35951141a.zip |
Rebind to the service after it was stopped
Diffstat (limited to 'core')
-rw-r--r-- | core/src/main/java/de/danoeh/antennapod/core/util/playback/PlaybackController.java | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/playback/PlaybackController.java b/core/src/main/java/de/danoeh/antennapod/core/util/playback/PlaybackController.java index eb189eb4e..428312393 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/playback/PlaybackController.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/playback/PlaybackController.java @@ -148,15 +148,7 @@ public class PlaybackController { } catch (IllegalArgumentException e) { // ignore } - - if(serviceBinder != null) { - serviceBinder.dispose(); - } - try { - activity.unbindService(mConnection); - } catch (IllegalArgumentException e) { - // ignore - } + unbind(); try { activity.unregisterReceiver(shutdownReceiver); @@ -173,6 +165,18 @@ public class PlaybackController { } } + private void unbind() { + if (serviceBinder != null) { + serviceBinder.dispose(); + } + try { + activity.unbindService(mConnection); + } catch (IllegalArgumentException e) { + // ignore + } + initialized = false; + } + /** * Should be called in the activity's onPause() method. */ @@ -256,6 +260,7 @@ public class PlaybackController { @Override public void onServiceDisconnected(ComponentName name) { playbackService = null; + initialized = false; Log.d(TAG, "Disconnected from Service"); } }; @@ -328,13 +333,11 @@ public class PlaybackController { }; private final BroadcastReceiver shutdownReceiver = new BroadcastReceiver() { - @Override public void onReceive(Context context, Intent intent) { if (playbackService != null) { - if (TextUtils.equals(intent.getAction(), - PlaybackService.ACTION_SHUTDOWN_PLAYBACK_SERVICE)) { - release(); + if (TextUtils.equals(intent.getAction(), PlaybackService.ACTION_SHUTDOWN_PLAYBACK_SERVICE)) { + unbind(); onShutdownNotification(); } } |