I am not able to find best solution to the situation where child activity changes data of parent activity.
I have activity A containing a list of items. Activity A starts activity B to show details to the user. User can run action and create activity C. Activity C creates new elements for the list in activity A.
The data are held in database so there is no problem with passing the data. I'm interested only in notification.
What is best solution to notify activity A that the data have been changed?
Currently I am aware of 2 solutions:
1) Return result by activity B and C with startActivityForResult(..)
and Extras
. The result would contain message "datachanged" -> true / false.
- I don't like this one because I am not able to send the message directly
2) Always refresh data in activity A on resume.
- Isn't that waste of processing?
3) Send Intent from activity C to activity A (broadcasts)
The solution I have found which are almost certainly wrong:
4) Save in some global state
- There is no global state (am I right?). We shouldn't do that as there is an extra abstraction layer (intents).
5) use getParent() to use parent activity
- The parent activity may be destroyed and recreated on return
Isn't there some other more light-weighy messanger system beetween activities? Something like Handler
and Messanger
in Activity-Service communiction. Maybe there shouldn't be one because it's against design?