android: Avoid races between FragmentManager and state saving
authorTobias Brunner <tobias@strongswan.org>
Thu, 28 Apr 2016 17:35:56 +0000 (19:35 +0200)
committerTobias Brunner <tobias@strongswan.org>
Mon, 2 May 2016 16:38:15 +0000 (18:38 +0200)
onSaveInstanceState is apparently called after pausing the fragment and after
that committing any FragmentTransactions causes an IllegalStateException.
We could use commitAllowingStateLoss() but that's not really necessary
as we don't need to update when we are not active anyway.  We also don't
update the view directly after registration as this happens
asynchronously, i.e. we might be paused when it finishes.

src/frontends/android/app/src/main/java/org/strongswan/android/ui/ImcStateFragment.java

index bf5eaf6..ab8dfc2 100644 (file)
@@ -66,7 +66,6 @@ public class ImcStateFragment extends Fragment implements VpnStateListener
                {
                        mService = ((VpnStateService.LocalBinder)service).getService();
                        mService.registerListener(ImcStateFragment.this);
-                       updateView();
                }
        };
 
@@ -147,9 +146,9 @@ public class ImcStateFragment extends Fragment implements VpnStateListener
        }
 
        @Override
-       public void onStart()
+       public void onResume()
        {
-               super.onStart();
+               super.onResume();
                if (mService != null)
                {
                        mService.registerListener(this);
@@ -158,9 +157,9 @@ public class ImcStateFragment extends Fragment implements VpnStateListener
        }
 
        @Override
-       public void onStop()
+       public void onPause()
        {
-               super.onStop();
+               super.onPause();
                if (mService != null)
                {
                        mService.unregisterListener(this);