Catching OOM on low memory devices while copying the album art for the Remote Control Client

This commit is contained in:
Karim Abou Zeid 2015-10-09 15:53:24 +02:00
commit 08feeff853

View file

@ -31,6 +31,7 @@ import android.support.annotation.Nullable;
import android.view.View; import android.view.View;
import android.widget.Toast; import android.widget.Toast;
import com.kabouzeid.gramophone.BuildConfig;
import com.kabouzeid.gramophone.R; import com.kabouzeid.gramophone.R;
import com.kabouzeid.gramophone.appwidget.WidgetMedium; import com.kabouzeid.gramophone.appwidget.WidgetMedium;
import com.kabouzeid.gramophone.helper.PlayingNotificationHelper; import com.kabouzeid.gramophone.helper.PlayingNotificationHelper;
@ -450,14 +451,16 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP
.postProcessor(new BitmapProcessor() { .postProcessor(new BitmapProcessor() {
@Override @Override
public Bitmap process(Bitmap bitmap) { public Bitmap process(Bitmap bitmap) {
// RemoteControlClient wants to recycle the bitmaps thrown at it, so we need
// to make sure not to hand out our cache copy
Bitmap.Config config = bitmap.getConfig(); Bitmap.Config config = bitmap.getConfig();
if (config == null) { if (config == null) {
config = Bitmap.Config.ARGB_8888; config = Bitmap.Config.ARGB_8888;
} }
bitmap = bitmap.copy(config, false); try {
return bitmap.copy(bitmap.getConfig(), true); return bitmap.copy(config, false);
} catch (OutOfMemoryError e) {
if (BuildConfig.DEBUG) e.printStackTrace();
return null;
}
} }
}).build(), }).build(),
new SimpleImageLoadingListener() { new SimpleImageLoadingListener() {