Fixed MediaRouterPlayService being killed on screen rotate.

This commit is contained in:
Felix Ableitner 2014-04-28 09:13:34 +02:00
parent b016780fca
commit 5747680e6a
2 changed files with 15 additions and 8 deletions

View file

@ -20,10 +20,17 @@
android:label="@string/app_name" android:label="@string/app_name"
android:theme="@style/Theme.AppCompat.Light" > android:theme="@style/Theme.AppCompat.Light" >
<!--
NOTE: configChanges is needed to avoid MediaRouterPlayService being
killed on screen rotate. (why do you do this, Google???).
This comes with some rendering issues on screen rotate (sometimes)
on Android 4.4 (but that's not my error).
-->
<activity <activity
android:name="com.github.nutomic.controldlna.gui.MainActivity" android:name="com.github.nutomic.controldlna.gui.MainActivity"
android:label="@string/app_name" android:label="@string/app_name"
android:launchMode="singleTop" > android:launchMode="singleTop"
android:configChanges="orientation|keyboardHidden|screenSize" >
<intent-filter android:label="@string/app_name" > <intent-filter android:label="@string/app_name" >

View file

@ -109,7 +109,7 @@ public class MediaRouterPlayService extends Service {
/* /*
* Stops foreground mode and notification if the current route * 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 = private MediaRouter.Callback mRouteRemovedCallback =
new MediaRouter.Callback() { new MediaRouter.Callback() {
@ -117,6 +117,9 @@ public class MediaRouterPlayService extends Service {
public void onRouteRemoved(MediaRouter router, RouteInfo route) { public void onRouteRemoved(MediaRouter router, RouteInfo route) {
if (route.equals(mCurrentRoute)) if (route.equals(mCurrentRoute))
stopForeground(true); stopForeground(true);
if (!mBound)
stopSelf();
} }
}; };
@ -172,12 +175,8 @@ public class MediaRouterPlayService extends Service {
*/ */
@Override @Override
public boolean onUnbind(Intent intent) { public boolean onUnbind(Intent intent) {
new Handler().postDelayed(new Runnable() { if (!mPollingStatus)
public void run() { stopSelf();
if (!mPollingStatus && !mBound)
stopSelf();
}
}, 5000);
mBound = false; mBound = false;
return super.onUnbind(intent); return super.onUnbind(intent);
} }
@ -342,6 +341,7 @@ public class MediaRouterPlayService extends Service {
stop(); stop();
if (!mBound) if (!mBound)
stopSelf(); stopSelf();
mPollingStatus = false;
return false; return false;
} }
} }