I have a RecyclerView inside a Fragment class, and I have a Service class where I wanted to add Item into my RecyclerView. The problem is I have no any idea on how can I possibl
First thing first, you must grasp the concept of event bus. In Otto doc, you can only see technical details about how event bus working in text. So for explanation sake, we borrow from EventBus. Here the images explaining how event bus working: Here are 3 parts:
Producer can only sent event. So you need to sent only event. Of course you can add 'payload' to event. So, to send the event, you can use something like:
bus.post(new SampleEvent("Your Data"));
Event is only a pojo class, something like this:
public class SampleEvent {
private String message;
public SampleEvent(String message) {
this.message = message;
}
public getMessage() {
return message;
}
}
or even a blank class:
public class BlankEvent {
}
Then you should Subscribe for waiting and receiving the event with:
@Subscribe
public void getMessage(SampleEvent event) {
String message = event.getMessage();
// Process the message here.
}
I think, by reading this simple explanation you will understand what are the problems in your code.
But I suggesting you use EventBus instead. OttoBus is deprecated now. Don't be afraid of the learning curve, because they share the same concept.