[Android] Release BackgroundManager sooner

Geoffrey Métais git at videolan.org
Tue Jul 18 15:34:52 CEST 2017


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Jul 18 15:07:00 2017 +0200| [ad482abedbb14040c71b68df0d62d81629cf1dcf] | committer: Geoffrey Métais

Release BackgroundManager sooner

> https://code.videolan.org/videolan/vlc-android/commit/ad482abedbb14040c71b68df0d62d81629cf1dcf
---

 .../src/org/videolan/vlc/gui/tv/MainTvActivity.java       |  5 ++++-
 .../org/videolan/vlc/gui/tv/MediaItemDetailsFragment.java | 15 ++++++++-------
 .../vlc/gui/tv/browser/MediaLibBrowserFragment.java       | 15 ++++++++++++++-
 .../vlc/gui/tv/browser/SortedBrowserFragment.java         | 10 +++++++++-
 4 files changed, 35 insertions(+), 10 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/tv/MainTvActivity.java b/vlc-android/src/org/videolan/vlc/gui/tv/MainTvActivity.java
index 2ff382c4c..a5595916a 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/MainTvActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/MainTvActivity.java
@@ -157,7 +157,7 @@ public class MainTvActivity extends BaseTvActivity implements OnItemViewSelected
 
         mBrowseFragment.setBrandColor(ContextCompat.getColor(this, R.color.orange800));
         mBackgroundManager = BackgroundManager.getInstance(this);
-        mBackgroundManager.attachToView(findViewById(R.id.tv_container));
+        mBackgroundManager.setAutoReleaseOnStop(false);
         TvUtil.clearBackground(mBackgroundManager);
     }
 
@@ -221,6 +221,8 @@ public class MainTvActivity extends BaseTvActivity implements OnItemViewSelected
             setmedialibraryListeners();
         } else
             setupMediaLibraryReceiver();
+        if (!mBackgroundManager.isAttached())
+            mBackgroundManager.attach(getWindow());
     }
 
     @Override
@@ -231,6 +233,7 @@ public class MainTvActivity extends BaseTvActivity implements OnItemViewSelected
         if (mService != null)
             mService.removeCallback(this);
         mMediaLibrary.removeMediaUpdatedCb();
+        mBackgroundManager.release();
     }
 
     @Override
diff --git a/vlc-android/src/org/videolan/vlc/gui/tv/MediaItemDetailsFragment.java b/vlc-android/src/org/videolan/vlc/gui/tv/MediaItemDetailsFragment.java
index 20498acf0..0c83ac753 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/MediaItemDetailsFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/MediaItemDetailsFragment.java
@@ -28,7 +28,6 @@ import android.graphics.Bitmap;
 import android.net.Uri;
 import android.os.Build;
 import android.os.Bundle;
-import android.support.annotation.Nullable;
 import android.support.v17.leanback.app.BackgroundManager;
 import android.support.v17.leanback.app.DetailsFragment;
 import android.support.v17.leanback.widget.Action;
@@ -81,20 +80,22 @@ public class MediaItemDetailsFragment extends DetailsFragment implements Playbac
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         mBackgroundManager = BackgroundManager.getInstance(getActivity());
+        mBackgroundManager.setAutoReleaseOnStop(false);
         buildDetails();
     }
 
     @Override
-    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
-        super.onActivityCreated(savedInstanceState);
-        mBackgroundManager.attachToView(getView());
+    public void onResume() {
+        super.onResume();
+        if (!mBackgroundManager.isAttached())
+            mBackgroundManager.attachToView(getView());
     }
 
-    public void onPause(){
+    public void onPause() {
+        mBackgroundManager.release();
         super.onPause();
-        if (mService != null && mService.isPlaying()) {
+        if (mService != null && mService.isPlaying())
             mService.stop();
-        }
     }
 
     @Override
diff --git a/vlc-android/src/org/videolan/vlc/gui/tv/browser/MediaLibBrowserFragment.java b/vlc-android/src/org/videolan/vlc/gui/tv/browser/MediaLibBrowserFragment.java
index 9883d4e3e..412f44e7b 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/browser/MediaLibBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/browser/MediaLibBrowserFragment.java
@@ -49,12 +49,12 @@ public abstract class MediaLibBrowserFragment extends GridFragment implements On
         super.onCreate(savedInstanceState);
         mMediaLibrary = VLCApplication.getMLInstance();
         mBackgroundManager = BackgroundManager.getInstance(getActivity());
+        mBackgroundManager.setAutoReleaseOnStop(false);
     }
 
     @Override
     public void onActivityCreated(@Nullable Bundle savedInstanceState) {
         super.onActivityCreated(savedInstanceState);
-        mBackgroundManager.attachToView(getView());
         setOnItemViewSelectedListener(this);
     }
 
@@ -65,6 +65,19 @@ public abstract class MediaLibBrowserFragment extends GridFragment implements On
             TvUtil.updateBackground(mBackgroundManager, mSelectedItem);
     }
 
+    @Override
+    public void onResume() {
+        super.onResume();
+        if (!mBackgroundManager.isAttached())
+            mBackgroundManager.attachToView(getView());
+    }
+
+    @Override
+    public void onPause() {
+        super.onPause();
+        mBackgroundManager.release();
+    }
+
     public void refresh() {
         if (!mMediaLibrary.isWorking())
             mMediaLibrary.reload();
diff --git a/vlc-android/src/org/videolan/vlc/gui/tv/browser/SortedBrowserFragment.java b/vlc-android/src/org/videolan/vlc/gui/tv/browser/SortedBrowserFragment.java
index 43d66d947..08a840353 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/browser/SortedBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/browser/SortedBrowserFragment.java
@@ -100,13 +100,13 @@ public abstract class SortedBrowserFragment extends BrowseFragment implements Br
         setHeadersState(HEADERS_ENABLED);
         setBrandColor(ContextCompat.getColor(getActivity(), R.color.orange800));
         mBackgroundManager = BackgroundManager.getInstance(getActivity());
+        mBackgroundManager.setAutoReleaseOnStop(false);
     }
 
     @Override
     public void onActivityCreated(Bundle savedInstanceState) {
         super.onActivityCreated(savedInstanceState);
         setHeadersState(HEADERS_HIDDEN);
-        mBackgroundManager.attachToView(getView());
         setOnItemViewSelectedListener(this);
         if (mAdapter.size() == 0)
             browse();
@@ -123,6 +123,14 @@ public abstract class SortedBrowserFragment extends BrowseFragment implements Br
     public void onResume() {
         super.onResume();
         VLCApplication.storeData(CURRENT_BROWSER_LIST, mVideosList);
+        if (!mBackgroundManager.isAttached())
+            mBackgroundManager.attachToView(getView());
+    }
+
+    @Override
+    public void onPause() {
+        super.onPause();
+        mBackgroundManager.release();
     }
 
     @Override



More information about the Android mailing list