How to notify from B-activity that the list data has been changed?

I have an Activity ItemList.java . When the user clicks on an item. This is the beginning of a new activity .let say ItemDetailAcitivty.java

What I want to do is when the user clicks the ItemDetailAcitivty.java button. He then had to tell ItemList.java update the list of items. I know that myListAdapter.notifyDataSetChanged() update the list. But how ItemList.java will know when to change data

I DONT for a static method or variables. I know how to use handlers, but I don’t know how to pass the handler to other actions.

What I think is to create my own Event / Listener and associate it with this list, so when the event fires, then change the list, most likely it could be a Broadcast receiver to help me?

+4
source share
3 answers

A better way would be to use an observer pattern (see http://en.wikipedia.org/wiki/Observer_pattern ), but you can make a public static method in ItemList.java containing a call to myListAdapter.notifyDataSetChanged() .

+3
source

You can try startActivityForResult(intent_to_activity) and in the same itemlist class override the method: onActivityResult() . In this method, the value of the notification set is changed, and it should reflect.

+3
source

You really should not assume that the link to your old activity will be supported by Android. If all of this is database based, you really don't need to do anything to update the ItemList. If this is not the case, you can simply call myListAdapter.notifyDataSetChanged() in onResume() your ItemList action.

+1
source

Source: https://habr.com/ru/post/1387575/


All Articles