i currently have the problem that i don't know exactly how to manage my variables.
Currently I have 5 activities. And thereby 5 Java classes. From class 3 the Var. are always to be seen.
The first two classes are only provided with buttons. In the third class I defined my variables (public static int Money = 100). Over class 4 I come to class 5 with which the variables are changed (Butto (-10)). By implement an update I can change the var. by clicking on a button (In class 5) (e.g. 90 money).
Here's my problem. If I go to activity 4 now (with the back button to the right of the home button), it's still worth the old value (100). If I go to class 3, it´s still the same value. When I want to go back now I land on activity 2 which is empty. But when I go now again in 3 or 4, the values are updated (now 90 money). How can this be done directly?
What is the best way to deal with such variables? I certainly have 10 other values who are affected by the problem.
Thats the code in class 3, where I defind the Variable, equals class 4.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_class3);
//Header
TextView MoneyView = findViewById(R.id.outputmoney);
MoneyView.setText(String.valueOf(class3.money));......}
Thets the declaration in class 4 and 5
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_class4);
TextView moneyView = findViewById(R.id.outputmoney);
MoneyView.setText(String.valueOf(class3.money));
BG and thank you