Im trying to pass data between two activities using this subject:
How do I pass data between Activities in Android application?
with this answer:
In your current Activity, create a new Intent:
Intent i = new Intent(getApplicationContext(), NewActivity.class);
i.putExtra("new_variable_name","value");
startActivity(i);
Then in the new Activity, retrieve those values:
Bundle extras = getIntent().getExtras();
if (extras != null) {
String value = extras.getString("new_variable_name");
}
My problem is , I'm not success.. I have a game contains a value called coins but it is as a sharedperferences , here is the code of the sharedpreferences: (oncreate)
prefs = this.getSharedPreferences("myPrefsKey", Context.MODE_PRIVATE);
coins = prefs.getInt("key2", 0);
Now how do I get the amount of coins I got on the Shop(Shop.java) to buy things with them?