I can’t find a better solution to the situation when a child activity modifies the data of the parent activity.
I have an operation A containing a list of elements. Action A starts action B to show the details to the user. A user can trigger an action and create activity C. Activity C creates new items for the list in action A.
Data is stored in a database, so there is no problem with data transfer. I'm only interested in the notification.
What is the best solution to notify activity A that data has been changed?
I currently know 2 solutions:
1) Returns the result for types B and C with startActivityForResult(..)and Extras. The result will contain the message "datachanged" → true / false.
- I don’t like it because I cannot send a message directly
2) Always update the data in step A when resuming.
- Isn't that a waste of processing?
3) Send the intent from activity C to activity A (broadcast)
The solution I found that is almost certainly wrong:
4) Save in any global state
- There is no global state (am I right?). We should not do this, since there is an additional layer of abstraction (intention).
5) use getParent () to use parent activity
- Parent activity can be destroyed and recreated upon return
Is there any other lighter messaging system between activities? Something like Handler, and Messangerin the Activity-Service communication. Maybe there shouldn't be one, because it's against design?