android: Don't update state fragments when they are not displayed
authorTobias Brunner <tobias@strongswan.org>
Fri, 20 Sep 2013 12:07:40 +0000 (14:07 +0200)
committerTobias Brunner <tobias@strongswan.org>
Mon, 23 Sep 2013 10:01:42 +0000 (12:01 +0200)
Besides that updates don't make much sense when the fragments are not
displayed this fixes the following exception:
java.lang.IllegalStateException: Can not perform this action after
onSaveInstanceState

src/frontends/android/src/org/strongswan/android/ui/ImcStateFragment.java
src/frontends/android/src/org/strongswan/android/ui/VpnStateFragment.java

index ff58849..39f86b4 100644 (file)
@@ -136,12 +136,32 @@ public class ImcStateFragment extends Fragment implements VpnStateListener
        }
 
        @Override
+       public void onStart()
+       {
+               super.onStart();
+               if (mService != null)
+               {
+                       mService.registerListener(this);
+                       updateView();
+               }
+       }
+
+       @Override
+       public void onStop()
+       {
+               super.onStop();
+               if (mService != null)
+               {
+                       mService.unregisterListener(this);
+               }
+       }
+
+       @Override
        public void onDestroy()
        {
                super.onDestroy();
                if (mService != null)
                {
-                       mService.unregisterListener(this);
                        getActivity().getApplicationContext().unbindService(mServiceConnection);
                }
        }
index 3219bba..88f8df3 100644 (file)
@@ -144,6 +144,7 @@ public class VpnStateFragment extends Fragment implements VpnStateListener
                super.onStart();
                if (mService != null)
                {
+                       mService.registerListener(this);
                        updateView();
                }
        }
@@ -152,6 +153,10 @@ public class VpnStateFragment extends Fragment implements VpnStateListener
        public void onStop()
        {
                super.onStop();
+               if (mService != null)
+               {
+                       mService.unregisterListener(this);
+               }
                hideErrorDialog();
                hideProgressDialog();
        }
@@ -162,7 +167,6 @@ public class VpnStateFragment extends Fragment implements VpnStateListener
                super.onDestroy();
                if (mService != null)
                {
-                       mService.unregisterListener(this);
                        getActivity().getApplicationContext().unbindService(mServiceConnection);
                }
        }