]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
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 ff58849fc445ccfe88d4fc674365bb67240d6f74..39f86b460039089de1f406418c2319c7bdf33838 100644 (file)
@@ -135,13 +135,33 @@ public class ImcStateFragment extends Fragment implements VpnStateListener
                return view;
        }
 
+       @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 3219bba7aad1efee0c4a0dcb2178bacff3a970c9..88f8df377f2e24880f4eac87ddc9b60423e0fa1f 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);
                }
        }