0

I have a question. And I have a TextView (number of gold) in my MainActivity. In addition, I can access a Main2Activity with a button, in which I can make a purchase. So depending on which item was purchased, the corresponding amount of gold should be deducted from the TextView.

Now I don't know how to do that, because if I re-initialize the same TextView in the second activity, my app crashes. Or, when im in the Main2Activity and press the back button on my phone, how i can recognize that, and update the new value of the TextView in the MainActivity.

Thank you for the answers

Devjejd
  • 7
  • 1
  • When moving from Activity to Activity, it is useless to change something in the TextView of another activity. You can use `Intent.putExtra` in order to pass values between activities, if that's what you mean. – Eldar B. Mar 31 '20 at 17:01
  • But if I am in the second activity and only use the back button on my phone, can I also hand over an intent? – Devjejd Mar 31 '20 at 17:10
  • 2
    You can open the second Activity with startActivityForResult and pass back the intent to MainActivity from SecondActivity on back press or however you want to handle it – p.mathew13 Mar 31 '20 at 17:21
  • check out this: https://stackoverflow.com/questions/10407159/how-to-manage-startactivityforresult-on-android – Sai Vihari Mar 31 '20 at 17:32

0 Answers0