I made an activity that increases a counter by one if the answer is correct, and decreases a counter by one if the answer is wrong. I have two different counters, and I modify them alternately.
So far everything works, but I would like to add to it so that if an answer is correct a new activity is opened. Here the user will decide whether the counter will be increased or not.
I have spent one day on it so far, but have not been successful.
Because you need only two counters, I will propose one very simple sollution, not “fancy” or “object oriented”, just simple and understandable.
Use two static variables in the class of your main activity, let say:
Set them before starting other activities which need them:
Use them directly in your other activities. Write back their values in onActivityResult():
Before writing them back you can also check if their values are changed:
Thats all. Forget all complicated sentences like “observer design paradigm”, they can’t give you nothing here but lost time.
Edit:
If by some reason you don’t want to use static variables, you can subclass Application (android.app.Application) and declare normal variables there. Then in every activity you can get your application object through getApplication() and access your common variables there.