[Android] Ignore Network change sticky behavior

Geoffrey Métais git at videolan.org
Tue Nov 22 17:05:43 CET 2016


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Nov 22 17:04:27 2016 +0100| [13becfac8eac8c97ff778e9366eed4db5df3de64] | committer: Geoffrey Métais

Ignore Network change sticky behavior

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

 .../videolan/vlc/gui/tv/browser/BaseTvActivity.java | 21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/tv/browser/BaseTvActivity.java b/vlc-android/src/org/videolan/vlc/gui/tv/browser/BaseTvActivity.java
index c9dc4b8..caf9030 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/browser/BaseTvActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/browser/BaseTvActivity.java
@@ -48,6 +48,7 @@ import org.videolan.vlc.util.WeakHandler;
 public abstract class BaseTvActivity extends PlaybackServiceActivity {
     protected Medialibrary mMediaLibrary;
     protected SharedPreferences mSettings;
+    boolean mRegistering = false;
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
@@ -67,6 +68,7 @@ public abstract class BaseTvActivity extends PlaybackServiceActivity {
         storageFilter.addAction(Intent.ACTION_MEDIA_EJECT);
         storageFilter.addDataScheme("file");
 
+        mRegistering = true;
         registerReceiver(mExternalDevicesReceiver, networkFilter);
         registerReceiver(mExternalDevicesReceiver, storageFilter);
     }
@@ -88,28 +90,23 @@ public abstract class BaseTvActivity extends PlaybackServiceActivity {
 
     protected abstract void refresh();
     protected abstract void onNetworkUpdated();
-    protected void onExternelDeviceChange() {};
+    protected void onExternelDeviceChange() {}
 
     protected final BroadcastReceiver mExternalDevicesReceiver = new BroadcastReceiver() {
-        boolean connected = true;
         @Override
         public void onReceive(Context context, Intent intent) {
             if (mMediaLibrary.isWorking())
                 return;
+            if (mRegistering) {
+                mRegistering = false;
+                return;
+            }
             String action = intent.getAction();
             if (ConnectivityManager.CONNECTIVITY_ACTION.equals(action)) {
                 final NetworkInfo networkInfo = ((ConnectivityManager) VLCApplication.getAppContext().getSystemService(
                         Context.CONNECTIVITY_SERVICE)).getActiveNetworkInfo();
-                if (networkInfo == null || networkInfo.getState() == NetworkInfo.State.CONNECTED) {
-                    if (networkInfo == null){
-                        if (connected)
-                            connected = false;
-                        else
-                            return; //block consecutive calls when disconnected
-                    } else
-                        connected = true;
+                if (networkInfo != null && networkInfo.getState() == NetworkInfo.State.CONNECTED)
                     onNetworkUpdated();
-                }
 
             } else if (action.equalsIgnoreCase(Intent.ACTION_MEDIA_MOUNTED)) {
                 mStorageHandlerHandler.sendEmptyMessageDelayed(ACTION_MEDIA_MOUNTED, 500);
@@ -126,7 +123,7 @@ public abstract class BaseTvActivity extends PlaybackServiceActivity {
 
     private static class FileBrowserFragmentHandler extends WeakHandler<BaseTvActivity> {
 
-        public FileBrowserFragmentHandler(BaseTvActivity owner) {
+        FileBrowserFragmentHandler(BaseTvActivity owner) {
             super(owner);
         }
 



More information about the Android mailing list