I have made an app where i'm doing some calculation and storing it in shared preference what i'm trying to do is get that calculated amount and show it in homeactivity where i'm not doing calculation. Just getting the data of shared preference.
What i know is that i can use intent to pass data but how to get value as exactly it changes in mainactivity because in homeactivity it will be shown as just available balance. Here is how i'm doing calculation
int total = (train_ticket_amount == null || train_ticket_amount.equals("") ? 0:Integer.parseInt(train_ticket_amount))
+ (bus_ticket_amount == null || bus_ticket_amount.equals("")? 0:Integer.parseInt(bus_ticket_amount))
+ (bike_amount == null || bike_amount.equals("")? 0:Integer.parseInt(bike_amount))
+ (share_rickshaw_amount == null || share_rickshaw_amount.equals("")? 0:Integer.parseInt(share_rickshaw_amount));
result = Integer.parseInt(textavailablebalance2) - total;
final_amount = textAvailableBalance1.getText().toString();
if(!expense_amount.isEmpty())
result+=Integer.parseInt(expense_amount);
textAvailableBalance1.setText(Integer.toString(result));
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putInt("price", result);
editor.apply();
and calling it in onCreate
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
result = settings.getInt("price",3000);
textAvailableBalance1.setText(String.valueOf(result));
The calculated amount is getting saved in shared preference in mainactivity but i want the same getting stored in homeactivity without doing calculation in homeactiivty is there a way to do so