I just started learning android development and thought I'd make a bill splitting app. However, I just started learning a multipage activitiy however I have no clue how to get data from other activities.
So what I'm trying to do is take a calculated amount of money from the Main Activity and display a summary on the second page.
int friendsInit = 1;
float collectAmount = splitCalc();
/* Friends increment/decrement functions */
public void friendIncrement(View view) {
friendsInit = friendsInit + 1;
friendsUpdate(friendsInit);
}
public void friendsDecrement(View view) {
if (friendsInit > 1) {
friendsInit = friendsInit - 1;
}
friendsUpdate(friendsInit);
}
/* Split calculations and update */
/*Rounding procedure*/
public static float round(float d, int decimalPlace) {
BigDecimal bd = new BigDecimal(Float.toString(d));
bd = bd.setScale(decimalPlace, BigDecimal.ROUND_HALF_UP);
return bd.floatValue();
}
public float splitCalc() {
EditText amountText = (EditText) findViewById(R.id.amount);
float number = Float.valueOf(amountText.getText().toString());
float collectAmount = round(number / (friendsInit + 1), 2);
return collectAmount;
}
So I want to use the collectAmount variable in the second activity. I did a little searching around and I found that you use.
float collectAmount = MainActivity.collectAmount;
But it gives me the error, "non-static field cannot be referenced from a static context". I'm not sure what this means or how to remedy it.
Any guidance on how to fix this issue would be appreciated or if there is a better way of storing data in your application.