[Android] TV: Cancel update when activity is paused

Geoffrey Métais git at videolan.org
Thu Apr 20 17:43:05 CEST 2017


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Apr 20 17:17:19 2017 +0200| [42b997e7b4a19dce6ffca02d9696b1f9b832a423] | committer: Geoffrey Métais

TV: Cancel update when activity is paused

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

 .../src/org/videolan/vlc/gui/tv/MainTvActivity.java       | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 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 530cc18..1be75ab 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/MainTvActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/MainTvActivity.java
@@ -219,6 +219,8 @@ public class MainTvActivity extends BaseTvActivity implements OnItemViewSelected
 
     @Override
     protected void onPause() {
+        if (mUpdateTask != null)
+            mUpdateTask.cancel(true);
         super.onPause();
         if (mService != null)
             mService.removeCallback(this);
@@ -416,16 +418,21 @@ public class MainTvActivity extends BaseTvActivity implements OnItemViewSelected
 
         @Override
         protected Void doInBackground(Void... params) {
+            if (isCancelled())
+                return null;
             videoList = mMediaLibrary.getVideos();
-            if (showHistory)
+            if (showHistory && !isCancelled())
                 history = VLCApplication.getMLInstance().lastMediaPlayed();
             return null;
         }
 
         @Override
+        protected void onCancelled() {
+            mUpdateTask = null;
+        }
+
+        @Override
         protected void onPostExecute(Void result) {
-            if (!isVisible())
-                return;
             mHandler.sendEmptyMessage(HIDE_LOADING);
             mVideoAdapter = new ArrayObjectAdapter(
                     new CardPresenter(mContext));
@@ -483,6 +490,8 @@ public class MainTvActivity extends BaseTvActivity implements OnItemViewSelected
             mOtherAdapter.add(new CardPresenter.SimpleCard(ID_LICENCE, getString(R.string.licence), R.drawable.ic_default_cone));
             mRowsAdapter.add(new ListRow(miscHeader, mOtherAdapter));
             mBrowseFragment.setSelectedPosition(Math.min(mBrowseFragment.getSelectedPosition(), mRowsAdapter.size()-1));
+            if (!isVisible())
+                return;
             mBrowseFragment.setAdapter(mRowsAdapter);
         }
     }



More information about the Android mailing list