android: Avoid races between FragmentManager and state saving

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.
This commit is contained in:
Tobias Brunner
2016-05-02 18:38:15 +02:00
parent 73a6bec3fc
commit 7ab8ec7ad0
@@ -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);