java - Why does the code run a command, even if its if statement isn't fulfilled? -
when run code in debug mode, can see, value "ooy" content set (and correct this) value "skii". code still starts activity "game.class", , activity "tutorial.class" in background. how can solve this?
mainscreen:
public class mainscreen extends activity implements onclicklistener { public static final string prefs_name = "myprefsfile1"; string ooy; string skii; super.oncreate(savedinstancestate); @override public void oncreate(bundle savedinstancestate) { setcontentview(r.layout.activity_main_screen); sharedpreferences tutoask = getsharedpreferences(prefs_name, 0); ooy = tutoask.getstring("skipmessage", "not checked"); skii = "checked"; @override public void onclick(view v) { int id = v.getid(); if (id == r.id.btn_start) { startactivity(new intent(this, tutorial.class)); if (ooy.equals(skii)){ startactivity(new intent(this, game.class)); } } tutorial:
public class tutorial extends activity implements onclicklistener { button btn; public checkbox checkbox1; string checkboxresult = "not checked"; public static final string prefs_name = "myprefsfile1"; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_tutorial); btn = (button) findviewbyid(r.id.startut); btn.setonclicklistener( this); checkbox1 = (checkbox) findviewbyid(r.id.checkbox1); } @override public void onclick(view v) { if (checkbox1.ischecked()){ checkboxresult = "checked"; sharedpreferences tutoask = getsharedpreferences(prefs_name, 0); sharedpreferences.editor editor = tutoask.edit(); editor.putstring("skipmessage", checkboxresult); // commit edits! editor.commit(); } startactivity(new intent(this, game.class)); finish(); } }
are saying 2 variables have different values? sorry, sentence difficult understand.
if variables not equal execute inside if command since have not (!) command.
if not equal execute command:
startactivity(new intent(this,game.class)); i not sure want , actual problem is. have 2 variables not equal values; when check two, not equal, command inside if executed. should since have not statement.
Comments
Post a Comment