diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 8959454..5fe10e4 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -20,10 +20,17 @@ android:label="@string/app_name" android:theme="@style/Theme.AppCompat.Light" > + + android:launchMode="singleTop" + android:configChanges="orientation|keyboardHidden|screenSize" > diff --git a/src/com/github/nutomic/controldlna/mediarouter/MediaRouterPlayService.java b/src/com/github/nutomic/controldlna/mediarouter/MediaRouterPlayService.java index 5377ad6..268a85b 100644 --- a/src/com/github/nutomic/controldlna/mediarouter/MediaRouterPlayService.java +++ b/src/com/github/nutomic/controldlna/mediarouter/MediaRouterPlayService.java @@ -109,7 +109,7 @@ public class MediaRouterPlayService extends Service { /* * Stops foreground mode and notification if the current route - * has been removed. + * has been removed. If the service is not bound, stops it. */ private MediaRouter.Callback mRouteRemovedCallback = new MediaRouter.Callback() { @@ -117,6 +117,9 @@ public class MediaRouterPlayService extends Service { public void onRouteRemoved(MediaRouter router, RouteInfo route) { if (route.equals(mCurrentRoute)) stopForeground(true); + + if (!mBound) + stopSelf(); } }; @@ -172,12 +175,8 @@ public class MediaRouterPlayService extends Service { */ @Override public boolean onUnbind(Intent intent) { - new Handler().postDelayed(new Runnable() { - public void run() { - if (!mPollingStatus && !mBound) - stopSelf(); - } - }, 5000); + if (!mPollingStatus) + stopSelf(); mBound = false; return super.onUnbind(intent); } @@ -342,6 +341,7 @@ public class MediaRouterPlayService extends Service { stop(); if (!mBound) stopSelf(); + mPollingStatus = false; return false; } }