From: Tobias Brunner Date: Fri, 20 Sep 2013 12:07:40 +0000 (+0200) Subject: android: Don't update state fragments when they are not displayed X-Git-Tag: 5.1.1dr4~14 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b4a5b185fcf86e58ae2f002c7cdcf3afef172e1b;p=thirdparty%2Fstrongswan.git android: Don't update state fragments when they are not displayed 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 --- diff --git a/src/frontends/android/src/org/strongswan/android/ui/ImcStateFragment.java b/src/frontends/android/src/org/strongswan/android/ui/ImcStateFragment.java index ff58849fc4..39f86b4600 100644 --- a/src/frontends/android/src/org/strongswan/android/ui/ImcStateFragment.java +++ b/src/frontends/android/src/org/strongswan/android/ui/ImcStateFragment.java @@ -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); } } diff --git a/src/frontends/android/src/org/strongswan/android/ui/VpnStateFragment.java b/src/frontends/android/src/org/strongswan/android/ui/VpnStateFragment.java index 3219bba7aa..88f8df377f 100644 --- a/src/frontends/android/src/org/strongswan/android/ui/VpnStateFragment.java +++ b/src/frontends/android/src/org/strongswan/android/ui/VpnStateFragment.java @@ -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); } }