Hello all i want to make use of a global integer variable that i shall be incrementing in 7 different activities according to the users right or wrong choise. The problem is that i every time i implement the variable in each different activity , the value is not kept. Instead i get the default value of the variable. What i want is that every increment i make to the variable is saved , when i use it again in the next variable. Any help appreciated. I have tried and failed :
public class MyApplication extends Application {
private int grade=0;
public int setGrade(int grade) {
this.grade = grade;
}
public int getGrade() {
return grade;
}
}
public class lessonOnePhoto extends Activity {
private int grade = ((MyApplication) this.getApplication()).getGrade();
if (rbtn[0].getText().toString().equals("Boy")) {
grade++;
}
else {
Toast.makeText(getApplicationContext(),"Wrong Choise",Toast.LENGHT_SHORT).show();
}
}