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
This commit is contained in:
Tobias Brunner
2013-09-23 12:01:42 +02:00
parent 561f94ae58
commit b4a5b185fc
2 changed files with 26 additions and 2 deletions
@@ -135,13 +135,33 @@ public class ImcStateFragment extends Fragment implements VpnStateListener
return view; 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 @Override
public void onDestroy() public void onDestroy()
{ {
super.onDestroy(); super.onDestroy();
if (mService != null) if (mService != null)
{ {
mService.unregisterListener(this);
getActivity().getApplicationContext().unbindService(mServiceConnection); getActivity().getApplicationContext().unbindService(mServiceConnection);
} }
} }
@@ -144,6 +144,7 @@ public class VpnStateFragment extends Fragment implements VpnStateListener
super.onStart(); super.onStart();
if (mService != null) if (mService != null)
{ {
mService.registerListener(this);
updateView(); updateView();
} }
} }
@@ -152,6 +153,10 @@ public class VpnStateFragment extends Fragment implements VpnStateListener
public void onStop() public void onStop()
{ {
super.onStop(); super.onStop();
if (mService != null)
{
mService.unregisterListener(this);
}
hideErrorDialog(); hideErrorDialog();
hideProgressDialog(); hideProgressDialog();
} }
@@ -162,7 +167,6 @@ public class VpnStateFragment extends Fragment implements VpnStateListener
super.onDestroy(); super.onDestroy();
if (mService != null) if (mService != null)
{ {
mService.unregisterListener(this);
getActivity().getApplicationContext().unbindService(mServiceConnection); getActivity().getApplicationContext().unbindService(mServiceConnection);
} }
} }