hi all I have a variable in first activity i need to add values returned from second activity and store it in this variables. Switching between activities happens multiple times…. Any ideas..?
here is a piece of code which stores current value each time and not the Sum of it…
double quantity = Double.parseDouble(s1[1]);
double amount = Double.parseDouble(s1[2]);
if(s1[3].equals(""))
{
totalint = (quantity*(amount));
Log.d("hitherebbbbbbb",((Double)totalint).toString());
grandTotal =+totalint;
}
else
{
deduction = Double.parseDouble(s1[3]);
totalint = ((quantity*(amount-deduction*amount/100)));
Log.d("hitherebbbbbbb",((Double)totalint).toString());
grandTotal =+totalint;
}
If the amount of variables stays the same you could always use sharedpreferences. They are super simple to use and you can add a sharedpreference listener to update your activity when a value is changed. If the amount of variables changes (eg you have 3 integers at one time but maybe your user can change it so you need 5) then I would do something a little more complex that may not be the best option but I like it because I find it more simple than a database. Let me know which scenario best describes your situation and I’ll get you more documentation.