當我在調試模式下運行我的代碼時,我可以看到,對於值「ooy」,另一個內容被設置(這將是正確的),而不是值「skii」。但是代碼仍然會啓動Activity「Game.class」和Activity「Tutorial.class」,但只能在後臺啓動。我該如何解決這個問題?爲什麼代碼運行一個命令,即使它的if語句沒有滿足?
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));
}
}
教程:
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 the edits!
editor.commit();
}
startActivity(new Intent(this, Game.class));
finish();
}
}
那麼顯然!ooy.equals(skii)是真的。什麼類型的ooy和skii是,以及它獲得價值的地方? – avjr 2015-03-31 19:45:21
@Skaros更新了問題。對不起,首先不是完整的代碼。 – 2015-03-31 19:55:54