I need to send a data from fragment B to A and add items to the Recyclerview
inside of the Fragment A, so I'm using the EventBus
to send the data and updating the list, the problem is, it only works in Debugging line by line, I mean, step by step and its weird.
So in the Fragment with the RecyclerView I register the Event and call the fragment.
override fun onStart() {
super.onStart()
if(!EventBus.getDefault().isRegistered(this)){
EventBus.getDefault().register(this)
}
}
@Subscribe(threadMode = ThreadMode.ASYNC)
fun onMessageEvent(event: TEvent?) {
adapter?.addItems(event?.model!!);
adapter?.notifyDataSetChanged();
}
The Adapter :
fun addItems(model: SubCategoryModel){
dataM.run {
add(model)
if(dataM.isNotEmpty()){
text.visibility = View.GONE;
imageView.visibility = View.GONE;
}
}
}
Fragment B where I fill the form with the information
EventBus.getDefault().post(TEvent(model))
activity?.onBackPressed()
Before using the EventBus I was using a Dialog in the same Fragment and it worked but now, it only updates the list if the app is running in a debug mode.
How can I update the other fragment thread ?