We've been doing this beer app this semester where you can add drinks as standard then press buttons and it will count beers and add a sum for you.
A problem we're having is that when we have pressed the buttons and the count is being summed up. When we close the application on the emulator, it doesn't remember the input. Is there any way to fix this?
Basically, we want it to remember Msum and Mcount, even after the app is closed an re-opened
the code is:
One file
public class ResourceManager {
private static ResourceManager singleton = new ResourceManager();
private ResourceManager() {}
public static ResourceManager getInstance() {
return singleton;
}
protected static int cost_beer = 0;
protected static int cost_drink = 0;
protected static int count = 0;
protected static int sum = 0;
}
Main File:
countButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
ResourceManager.getInstance().count++;
ResourceManager.getInstance().sum += ResourceManager.getInstance().cost_beer;
countTextView.setText("Du har drukket " + ResourceManager.getInstance().count + " enheter!");
sumTextView.setText("Sum:" + ResourceManager.getInstance().sum + "!");
}
});
drinkButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
ResourceManager.getInstance().count++;
ResourceManager.getInstance().sum += ResourceManager.getInstance().cost_drink;
countTextView.setText("You have been drinking " + ResourceManager.getInstance().count + " units!");
sumTextView.setText("Sum:" + ResourceManager.getInstance().sum + "!");
}
});
resetButton.setOnClickListener(new View.OnClickListener() {
public void onClick (View view) {
ResourceManager.getInstance().sum = 0;
ResourceManager.getInstance().count = 0;
countTextView.setText("You have been drinking " + ResourceManager.getInstance().count + " units!");
sumTextView.setText("Sum:" + ResourceManager.getInstance().sum + "!");
}
});