SharedPreferences sPref; final String SAVED_TEXT = "saved_text"; public void Check(View view) { sPref = getPreferences(MODE_PRIVATE); int progress = sPref.getInt(SAVED_TEXT, 2); if (progress==2) { Intent intent = new Intent(Main6Activity.this, Main7Activity.class); startActivity(intent); } if (progress==3) { Intent intent = new Intent(Main6Activity.this, Main8Activity.class); startActivity(intent); } if (progress==4) { Intent intent = new Intent(Main6Activity.this, Main9Activity.class); startActivity(intent); } if (progress==5) { Intent intent = new Intent(Main6Activity.this, Main10Activity.class); startActivity(intent); } if (progress==6) { Intent intent = new Intent(Main6Activity.this, Main11Activity.class); startActivity(intent); } if (progress==7) { Intent intent = new Intent(Main6Activity.this, Main12Activity.class); startActivity(intent); } if (progress==8) { Intent intent = new Intent(Main6Activity.this, Main13Activity.class); startActivity(intent); } if (progress==9) { Intent intent = new Intent(Main6Activity.this, Main14Activity.class); startActivity(intent); } if (progress==10) { Intent intent = new Intent(Main6Activity.this, Main15Activity.class); startActivity(intent); } if (progress==11) { Intent intent = new Intent(Main6Activity.this, Main16Activity.class); startActivity(intent); } if (progress==12) { Intent intent = new Intent(Main6Activity.this, Main17Activity.class); startActivity(intent); } if (progress==13) { Intent intent = new Intent(Main6Activity.this, Main18Activity.class); startActivity(intent); } if (progress==14) { Intent intent = new Intent(Main6Activity.this, Main19Activity.class); startActivity(intent); } } public void onClick(View view){ sPref = getPreferences(MODE_PRIVATE); SharedPreferences.Editor ed = sPref.edit(); ed.putInt(SAVED_TEXT, 2); ed.apply(); } 

PS with spaces and brackets everything is fine. When you click on a button in SAVED_TEXT, variable 2 should be saved, which, when you click on another button, will be read and checked for what this number is, if the resulting variable is equal to 2, for example, then another activity should open, but this does not happen.

  • one
    The error is most likely in the code. Probably you have its description from the compiler or from the logs - bring it, add a question with a description of what is wrong. Otherwise, do not answer your question, because Actually there is no question. - Yuriy SPb
  • I added a description. - Man1nHat
  • More details are needed. Be convinced to begin with that methods basically are caused. For example, something brought in the logs. Also, it will not work if these methods are in different activities. - Yuriy SPb
  • Is the Check(View view) method exactly called? Put the method code Log.d("TEST", "run Check"); and check in logcat. - Ivan
  • Not the topic, but . - post_zeew

0