Passing data between activities in Android
in your current activity, create an intent
Intent i = new Intent(getApplicationContext(), ActivityB.class);
i.putExtra(key, value);
startActivity(i);
then in the other activity, retrieve those values.
Bundle extras = getIntent().getExtras();
if(extras !=null) {
String value = extras.getString(key);
}
Use a global class:
public class GlobalClass extends Application
{
private float vitamin_a;
public float getVitaminA() {
return vitamin_a;
}
public void setVitaminA(float vitamin_a) {
this.vitamin_a = vitamin_a;
}
}
You can call the setters and the getters of this class from all other classes. Do do that, you need to make a GlobalClass-Object in every Actitity:
GlobalClass gc = (GlobalClass) getApplication();
Then you can call for example:
gc.getVitaminA()