EventBus is a library of Greenbot . This is very simple for all users how to implement and its basic use. Here I will also share examples for better understanding. What is EventBus? EventBus is subscribed/publish event bus to communication between components with limited lines of code, in short, its bus for events transfers the data between one activity(class) to another to reflect the changes based on our needs. That makes the data exchange between components like Activity, Fragment, Services, and any kind of backgrounds threads pretty easy. EventBus can handle the threading for us: events can be posted in threads different from the posting thread. Common use can be dealing with UI changes. In Android, UI changes must be done in the Main(UI) thread. In other words, networking or more time-consuming task cannot be handled in the Main thread, for that we must use AsyncTask or Handler to make it more smooth. Now we have one more options use EventBus to change the UI po...
We all know how to pass String, boolean, objects from one activity to another but if we want to pass ArrayList then?
So here I am giving you small example which help you to pass ArrayList from one activity to another.
1. Books.java
First, we write one class(Model), lets take example for Book for library project.
2. BookList.java
Create another class with inherits from ArrayList of Books model and implements the interface Parcelable.
There are basically two methods. One that writes the content into ArrayList and another that retrieves the content in form of ArrayList.
3. CallerActivity.java
MainActivity(CallerActivity) that pass content as a ArrayList to another activity(CalledActivity).
4. CalledActivity.java
This activity receives the content as a ArrayList which was pass from CallerActivity.
Hope this will help you.
Create another class with inherits from ArrayList of Books model and implements the interface Parcelable.
There are basically two methods. One that writes the content into ArrayList and another that retrieves the content in form of ArrayList.
3. CallerActivity.java
MainActivity(CallerActivity) that pass content as a ArrayList to another activity(CalledActivity).
4. CalledActivity.java
This activity receives the content as a ArrayList which was pass from CallerActivity.
Hope this will help you.
If you are satisfied then please give your comments.
Thanks for your Interest!!!
Comments
Post a Comment