OSDN Git Service

Eleven: Fix exception when leaving Eleven with nothing in the queue
authorlinus_lee <llee@cyngn.com>
Thu, 11 Dec 2014 19:03:45 +0000 (11:03 -0800)
committerlinus_lee <llee@cyngn.com>
Thu, 11 Dec 2014 19:05:33 +0000 (11:05 -0800)
It is possible for things to post to a handler even after the service has been destroyed
Fix is to shutdown the handlerthread in the onDestroy
Also set the subtitle text to alpha of 0 to not show on first launch

Change-Id: I76b5f4c4bc8a114660ced042ab02089bf279accb

res/layout/activity_player_fragment.xml
src/com/cyanogenmod/eleven/MusicPlaybackService.java

index 941a035..f0c8b9b 100644 (file)
@@ -64,7 +64,8 @@
             android:paddingBottom="6dp"
             android:background="@color/lyrics_background_color"
             android:textColor="@color/white"
-            android:textSize="@dimen/text_size_small"/>
+            android:textSize="@dimen/text_size_small"
+            android:alpha="0.0"/>
     </com.cyanogenmod.eleven.widgets.SquareFrame>
 
     <RelativeLayout
index cecacd4..b9a8073 100644 (file)
@@ -474,6 +474,7 @@ public class MusicPlaybackService extends Service {
     private long[] mAutoShuffleList = null;
 
     private MusicPlayerHandler mPlayerHandler;
+    private HandlerThread mHandlerThread;
 
     private BroadcastReceiver mUnmountReceiver = null;
 
@@ -574,12 +575,12 @@ public class MusicPlaybackService extends Service {
         // separate thread because the service normally runs in the process's
         // main thread, which we don't want to block. We also make it
         // background priority so CPU-intensive work will not disrupt the UI.
-        final HandlerThread thread = new HandlerThread("MusicPlayerHandler",
+        mHandlerThread = new HandlerThread("MusicPlayerHandler",
                 android.os.Process.THREAD_PRIORITY_BACKGROUND);
-        thread.start();
+        mHandlerThread.start();
 
         // Initialize the handler
-        mPlayerHandler = new MusicPlayerHandler(this, thread.getLooper());
+        mPlayerHandler = new MusicPlayerHandler(this, mHandlerThread.getLooper());
 
         // Initialize the audio manager and register any headset controls for
         // playback
@@ -696,6 +697,11 @@ public class MusicPlaybackService extends Service {
         // remove any pending alarms
         mAlarmManager.cancel(mShutdownIntent);
 
+        // Remove any callbacks from the handler
+        mPlayerHandler.removeCallbacksAndMessages(null);
+        // quit the thread so that anything that gets posted won't run
+        mHandlerThread.quitSafely();
+
         // Release the player
         mPlayer.release();
         mPlayer = null;
@@ -707,9 +713,6 @@ public class MusicPlaybackService extends Service {
         // remove the media store observer
         getContentResolver().unregisterContentObserver(mMediaStoreObserver);
 
-        // Remove any callbacks from the handler
-        mPlayerHandler.removeCallbacksAndMessages(null);
-
         // Close the cursor
         closeCursor();