First I'm still new to this android programming. I want to ask, why my switch always turn on when i start my app. When I turn it off and go to another activity and back to the first activity, the switch button turn on again Any clue ? I tried Android ToggleButton always check but i still don't get it.
switchStatus = (TextView) findViewById(R.id.View1);
mySwitch.setChecked(true);
mySwitch = (Switch) findViewById(R.id.switch1);
mySwitch.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
if(mySwitch.isChecked()){
mySwitch.setChecked(true);
switchStatus.setText("Switch is currently On");
onResume();
sendButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
}
});
}
else{
mySwitch.setChecked(false);
switchStatus.setText("Switch is currently OFF");
onPause();
}
}
});