I’ve saved an int when a button is saved (in the upgrade class), and the int is called in another activity (the play class). But whenever I replay the app, I first need to go to the upgrade activity before the i go to the play activity, otherwise the integers I have saved aren’t loaded properly.
public class Play extends Activity implements OnTouchListener {
MKZSurface ourSurfaceView;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
ourSurfaceView = new MKZSurface(this);
ourSurfaceView.setOnTouchListener(this);
setContentView(ourSurfaceView);
MYU = Upgrades.mYU;
BU = Upgrades.BU;
MBU = Upgrades.mBU;
RU = Upgrades.RU;
MRU = Upgrades.mRU;
}
And in the upgrades class I have saved these ints with a value using SharedPreferences. How do I load the data with the saved ints without the need to going to the upgrades page first?
You can retrieved your data without going back to Upgrades page if you have saved them using SharedPreferences. Use something like below to retrieve your data.
0 is the default value in case you haven’t saved any values.