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-20 14:07:40 +02:00
parent 561f94ae58
commit b4a5b185fc
2 changed files with 26 additions and 2 deletions

View 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);
}
}

View 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);
}
}