I have an Activity with a Switch Control
. With this switch control, the user can turn on/off a tcp server.
Now I have a similiar problem to here. If the Switch (and also the Server) is turned on and the orientation changes the onclicklistener
is called again and so also the server is started again.
I tried to handle this by checking if the client is null:
OnCheckedChangeListener listener = new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked) {
if (client == null)
startCubeSolverServer();
} else {
if (client != null)
stutdownCubeSolverServer();
}
}
};
but because the client object is a private variable of my activity it is reset to null each orientation change.
Is there an easy fix to don't run the changeHandler
if the value doesn't change in users view?