Reputation: 81
I have got 2 activities - "A" contains fragment with a list of conversations, "B" represents a conversation (shows it's messages), in B I can also send a new message. I would like to be able to update A's list of conversations every time a message is sent in B, so when I click android's back button, A activity's view is updated.
The core of the problem for me, is that I'm not starting A through an Intent when I click the android's back button, so I don't know how to get this effect.
Thank you for your help!
Upvotes: 1
Views: 70
Reputation: 10288
When A is on the backstack, there's no guarantee that an instance of A even exists in memory. The answer to the question of how to manipulate A from B is don't.
Some correct ways of doing it:
Parcelable
or Serializable
, you can pass it between activities via Intent
. You can pass it back from B to A if you start B for result and retrieve it from the Intent
returned to A's onActivityResult
.SharedPreferences
file.Service
. This would be faster than having each activity load it from persistent storage, but you may still need to make it persistent so you don't lose it when the Service
shuts down.Upvotes: 1