SlideShare a Scribd company logo
1 of 4
Download to read offline
What is EventBus Library and How Does it Work?
In this blog, we are going to discuss about the Eventbus library.
What is EventBus:
EventBus Is open Source android library that simplifies communication between
Activities, Fragments, Threads, Services, with Less code, better quality.When we
develop an android application we need to manage a lot of intercommunication
between android components which some time's become very difficult to manage.
Eventbus library makes this task easy to implement.
Why EventBus?
The main reason why we should use EventBus is loose coupling. Sometimes you want
to process specific events that are interested for multiple parts of your application like
presentation layer business layer and data layer so EventBus provides a easy solution
for this.
Some features of EventBus library:
1-Simple yet powerful:
2- Battle tested:
3-High Performance
4-Convenient Annotation based API
5-Event & Subscriber inheritance
you need to have four thing for implement EventBus:
1- A EventBus Object .
EventBus myEventBus = EventBus.getDefault();
2- A Event normal pojo class.
public class DataSyncEvent {
private final String syncStatusMessage;
public DataSyncEvent(String syncStatusMessage) {
this.syncStatusMessage = syncStatusMessage;
}
public String getSyncStatusMessage() {
return syncStatusMessage;
}
}
3- The sender which will send the event:
EventBus.getDefault().post(new DataSyncEvent("Sync SuccessFully”);
4- The subscriber is someone who will listen to our event.
@Subscribe
public void onEvent(DataSyncEvent syncStatusMessage)
{
Toast.makeText(this, syncStatusMessage.getSyncStatusMessage(),
Toast.LENGTH_SHORT).show();
}
The last two step are Register and unregister the Eventbus who want to listen to the
event. The best way is register in onStart method and unRegister in the onStop
method of activity.
@Override
protected void onStart() {
super.onStart();
EventBus.getDefault().register(this);
}
@Override
protected void onStop() {
super.onStop();
EventBus.getDefault().unregister(this);
}
Example of EventBus:
Let's take a simple example, In our project, if we want to Sync our data to the server
at the time of applicaiton launch, for this, simply start an intent service from the
launcher activity of your application and through intent service sync the data to the
server. After that notify the screen(Through EventBus library) which is currently
visible to user about syncing.
Implementation of EventBus:
Add the dependencies in the gradle file.
compile 'de.greenrobot:eventbus:2.4.0'
Intent service class which will start at the time of application launch.
public class SyncDataService extends IntentService
{
public SyncDataService()
{
super("SyncDataService");
}
@Override
protected void onHandleIntent(Intent intent)
{
//first check if internet is availabe or not.
if(DeviceManager.isInternetAvailableOnDevice())
{
// try
// {
// //write the code to sync the data to Server
//post the event after sync complete
EventBus.getDefault().post(new DataSyncEvent("Data
Sync SuccessFully"));
// }
// catch (RTITBException exception)
// {
//
LogManager.getInstance().addLog(exception.getExceptionCode(),exceptio
n.getMessage(),exception);
// }
}
}
}
The Maine Activity.
public class MainActivity extends AppCompatActivity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
//Register the EventBus
@Override
protected void onStart()
{
super.onStart();
EventBus.getDefault().register(this);
}
//UnRegister the EventBus
@Override
protected void onStop()
{
super.onStop();
EventBus.getDefault().unregister(this);
}
//The Method which will call every time when data sync to server
@Subscribe
public void onEvent(DataSyncEvent syncStatusMessage)
{
//you can do whatever you want releted with UI
Toast.makeText(this, syncStatusMessage.getMessage(),
Toast.LENGTH_SHORT).show();
}
}
If any other component of you applicaiton want to listen to the event then only we
need to register for the EventBus as mentioned in above method onStart and override
the method onEvent.
Conclusion:
Eventbus library is just like a radio frequency, if you wish to listen to any song, you
simply need to set the frequency to that station. Likewise, event bus library posts
events, if any component wants to listen that event then we need to register that
component for the EventBus object and we will get that event in onEvent Method.

More Related Content

What's hot

Firebase on Android: The Big Picture
Firebase on Android: The Big PictureFirebase on Android: The Big Picture
Firebase on Android: The Big PictureSriyank Siddhartha
 
Grow and Retain Users with Analytics and Push Notifications
Grow and Retain Users with Analytics and Push NotificationsGrow and Retain Users with Analytics and Push Notifications
Grow and Retain Users with Analytics and Push NotificationsAmazon Web Services
 
Event Sourcing your Angular and React applications
Event Sourcing your Angular and React applicationsEvent Sourcing your Angular and React applications
Event Sourcing your Angular and React applicationsMaurice De Beijer [MVP]
 
Introduction to Firebase
Introduction to FirebaseIntroduction to Firebase
Introduction to FirebaseMustafa Şenel
 
What is new in Firebase?
What is new in Firebase?What is new in Firebase?
What is new in Firebase?Sinan Yılmaz
 
Microservices on AWS using AWS Lambda and Docker Containers
Microservices on AWS using AWS Lambda and Docker ContainersMicroservices on AWS using AWS Lambda and Docker Containers
Microservices on AWS using AWS Lambda and Docker ContainersDanilo Poccia
 
R.A.P. (Rely on Android Platform)
R.A.P. (Rely on Android Platform)R.A.P. (Rely on Android Platform)
R.A.P. (Rely on Android Platform)Aditium
 
Connector API Apps
Connector API AppsConnector API Apps
Connector API AppsBizTalk360
 
Google Firebase
Google FirebaseGoogle Firebase
Google FirebaseAliZaidi94
 
Introduction to Firebase on Android
Introduction to Firebase on AndroidIntroduction to Firebase on Android
Introduction to Firebase on Androidamsanjeev
 
First Look at Azure Logic Apps (BAUG)
First Look at Azure Logic Apps (BAUG)First Look at Azure Logic Apps (BAUG)
First Look at Azure Logic Apps (BAUG)Daniel Toomey
 
Event-Sourcing your React-Redux applications
Event-Sourcing your React-Redux applicationsEvent-Sourcing your React-Redux applications
Event-Sourcing your React-Redux applicationsMaurice De Beijer [MVP]
 
Getting Started with Docker on AWS
Getting Started with Docker on AWSGetting Started with Docker on AWS
Getting Started with Docker on AWSAmazon Web Services
 
Go Serverless with Cosmos DB, Azure Functions and Blazor
Go Serverless with Cosmos DB, Azure Functions and BlazorGo Serverless with Cosmos DB, Azure Functions and Blazor
Go Serverless with Cosmos DB, Azure Functions and BlazorTimothy McAliley
 
Windows azure mobile services from start to rest
Windows azure mobile services from start to restWindows azure mobile services from start to rest
Windows azure mobile services from start to restAidan Casey
 
Azure Functions @ global azure day 2017
Azure Functions  @ global azure day 2017Azure Functions  @ global azure day 2017
Azure Functions @ global azure day 2017Sean Feldman
 
Introducing firebase
Introducing firebaseIntroducing firebase
Introducing firebaseFarouk Touzi
 

What's hot (20)

Firebase on Android: The Big Picture
Firebase on Android: The Big PictureFirebase on Android: The Big Picture
Firebase on Android: The Big Picture
 
Grow and Retain Users with Analytics and Push Notifications
Grow and Retain Users with Analytics and Push NotificationsGrow and Retain Users with Analytics and Push Notifications
Grow and Retain Users with Analytics and Push Notifications
 
Event Sourcing your Angular and React applications
Event Sourcing your Angular and React applicationsEvent Sourcing your Angular and React applications
Event Sourcing your Angular and React applications
 
Introduction to Firebase
Introduction to FirebaseIntroduction to Firebase
Introduction to Firebase
 
What is new in Firebase?
What is new in Firebase?What is new in Firebase?
What is new in Firebase?
 
Microservices on AWS using AWS Lambda and Docker Containers
Microservices on AWS using AWS Lambda and Docker ContainersMicroservices on AWS using AWS Lambda and Docker Containers
Microservices on AWS using AWS Lambda and Docker Containers
 
R.A.P. (Rely on Android Platform)
R.A.P. (Rely on Android Platform)R.A.P. (Rely on Android Platform)
R.A.P. (Rely on Android Platform)
 
Mastering Firebase Cloud Messaging
Mastering Firebase Cloud MessagingMastering Firebase Cloud Messaging
Mastering Firebase Cloud Messaging
 
Connector API Apps
Connector API AppsConnector API Apps
Connector API Apps
 
Google Firebase
Google FirebaseGoogle Firebase
Google Firebase
 
Introduction to Firebase on Android
Introduction to Firebase on AndroidIntroduction to Firebase on Android
Introduction to Firebase on Android
 
First Look at Azure Logic Apps (BAUG)
First Look at Azure Logic Apps (BAUG)First Look at Azure Logic Apps (BAUG)
First Look at Azure Logic Apps (BAUG)
 
Event-Sourcing your React-Redux applications
Event-Sourcing your React-Redux applicationsEvent-Sourcing your React-Redux applications
Event-Sourcing your React-Redux applications
 
Getting Started with Docker on AWS
Getting Started with Docker on AWSGetting Started with Docker on AWS
Getting Started with Docker on AWS
 
Event Source On Labs
Event Source On LabsEvent Source On Labs
Event Source On Labs
 
Go Serverless with Cosmos DB, Azure Functions and Blazor
Go Serverless with Cosmos DB, Azure Functions and BlazorGo Serverless with Cosmos DB, Azure Functions and Blazor
Go Serverless with Cosmos DB, Azure Functions and Blazor
 
Firebase
FirebaseFirebase
Firebase
 
Windows azure mobile services from start to rest
Windows azure mobile services from start to restWindows azure mobile services from start to rest
Windows azure mobile services from start to rest
 
Azure Functions @ global azure day 2017
Azure Functions  @ global azure day 2017Azure Functions  @ global azure day 2017
Azure Functions @ global azure day 2017
 
Introducing firebase
Introducing firebaseIntroducing firebase
Introducing firebase
 

Similar to Eventbus Library and How Does it Work?

Front-end. Global domination
Front-end. Global dominationFront-end. Global domination
Front-end. Global dominationStfalcon Meetups
 
Azure Functions.pptx
Azure Functions.pptxAzure Functions.pptx
Azure Functions.pptxYachikaKamra
 
Creating microservices architectures using node.js and Kubernetes
Creating microservices architectures using node.js and KubernetesCreating microservices architectures using node.js and Kubernetes
Creating microservices architectures using node.js and KubernetesPaul Goldbaum
 
Android application architecture
Android application architectureAndroid application architecture
Android application architectureRomain Rochegude
 
Serverless by Example: Building a Real-Time Chat System
Serverless by Example: Building a Real-Time Chat SystemServerless by Example: Building a Real-Time Chat System
Serverless by Example: Building a Real-Time Chat SystemAmazon Web Services
 
Using Data Science & Serverless Python to find apartment in Toronto
Using Data Science & Serverless Python to find apartment in TorontoUsing Data Science & Serverless Python to find apartment in Toronto
Using Data Science & Serverless Python to find apartment in TorontoDaniel Zivkovic
 
Asp.net+interview+questions+and+answers
Asp.net+interview+questions+and+answersAsp.net+interview+questions+and+answers
Asp.net+interview+questions+and+answersMohan Raj
 
Meteor Meet-up San Diego December 2014
Meteor Meet-up San Diego December 2014Meteor Meet-up San Diego December 2014
Meteor Meet-up San Diego December 2014Lou Sacco
 
Google Cloud Functions & Firebase Crash Course
Google Cloud Functions & Firebase Crash CourseGoogle Cloud Functions & Firebase Crash Course
Google Cloud Functions & Firebase Crash CourseDaniel Zivkovic
 
Introducing windows server_app_fabric
Introducing windows server_app_fabricIntroducing windows server_app_fabric
Introducing windows server_app_fabricMarco Titta
 
Building 12-factor Cloud Native Microservices
Building 12-factor Cloud Native MicroservicesBuilding 12-factor Cloud Native Microservices
Building 12-factor Cloud Native MicroservicesJakarta_EE
 
Easy integration of Bluemix services with your applications
Easy integration of Bluemix services with your applicationsEasy integration of Bluemix services with your applications
Easy integration of Bluemix services with your applicationsJack-Junjie Cai
 
Build Your Mobile App Faster with AWS Mobile Services (Part 1 - AWS)
Build Your Mobile App Faster with AWS Mobile Services (Part 1 - AWS)Build Your Mobile App Faster with AWS Mobile Services (Part 1 - AWS)
Build Your Mobile App Faster with AWS Mobile Services (Part 1 - AWS)Amazon Web Services
 
.NET Portfolio
.NET Portfolio.NET Portfolio
.NET Portfoliomwillmer
 
devworkshop-10_28_1015-amazon-conference-presentation
devworkshop-10_28_1015-amazon-conference-presentationdevworkshop-10_28_1015-amazon-conference-presentation
devworkshop-10_28_1015-amazon-conference-presentationAlex Wu
 
Microservices with asp dot net core, a next gen technology
Microservices with asp dot net core, a next gen technologyMicroservices with asp dot net core, a next gen technology
Microservices with asp dot net core, a next gen technologyEvincedev
 
Lecture 11 Firebase overview
Lecture 11 Firebase overviewLecture 11 Firebase overview
Lecture 11 Firebase overviewMaksym Davydov
 

Similar to Eventbus Library and How Does it Work? (20)

Front-end. Global domination
Front-end. Global dominationFront-end. Global domination
Front-end. Global domination
 
Frontend. Global domination.
Frontend. Global domination.Frontend. Global domination.
Frontend. Global domination.
 
Azure Functions.pptx
Azure Functions.pptxAzure Functions.pptx
Azure Functions.pptx
 
Creating microservices architectures using node.js and Kubernetes
Creating microservices architectures using node.js and KubernetesCreating microservices architectures using node.js and Kubernetes
Creating microservices architectures using node.js and Kubernetes
 
Android application architecture
Android application architectureAndroid application architecture
Android application architecture
 
Serverless by Example: Building a Real-Time Chat System
Serverless by Example: Building a Real-Time Chat SystemServerless by Example: Building a Real-Time Chat System
Serverless by Example: Building a Real-Time Chat System
 
Using Data Science & Serverless Python to find apartment in Toronto
Using Data Science & Serverless Python to find apartment in TorontoUsing Data Science & Serverless Python to find apartment in Toronto
Using Data Science & Serverless Python to find apartment in Toronto
 
Asp.net+interview+questions+and+answers
Asp.net+interview+questions+and+answersAsp.net+interview+questions+and+answers
Asp.net+interview+questions+and+answers
 
Firebase
Firebase Firebase
Firebase
 
Serverless computing
Serverless computingServerless computing
Serverless computing
 
Meteor Meet-up San Diego December 2014
Meteor Meet-up San Diego December 2014Meteor Meet-up San Diego December 2014
Meteor Meet-up San Diego December 2014
 
Google Cloud Functions & Firebase Crash Course
Google Cloud Functions & Firebase Crash CourseGoogle Cloud Functions & Firebase Crash Course
Google Cloud Functions & Firebase Crash Course
 
Introducing windows server_app_fabric
Introducing windows server_app_fabricIntroducing windows server_app_fabric
Introducing windows server_app_fabric
 
Building 12-factor Cloud Native Microservices
Building 12-factor Cloud Native MicroservicesBuilding 12-factor Cloud Native Microservices
Building 12-factor Cloud Native Microservices
 
Easy integration of Bluemix services with your applications
Easy integration of Bluemix services with your applicationsEasy integration of Bluemix services with your applications
Easy integration of Bluemix services with your applications
 
Build Your Mobile App Faster with AWS Mobile Services (Part 1 - AWS)
Build Your Mobile App Faster with AWS Mobile Services (Part 1 - AWS)Build Your Mobile App Faster with AWS Mobile Services (Part 1 - AWS)
Build Your Mobile App Faster with AWS Mobile Services (Part 1 - AWS)
 
.NET Portfolio
.NET Portfolio.NET Portfolio
.NET Portfolio
 
devworkshop-10_28_1015-amazon-conference-presentation
devworkshop-10_28_1015-amazon-conference-presentationdevworkshop-10_28_1015-amazon-conference-presentation
devworkshop-10_28_1015-amazon-conference-presentation
 
Microservices with asp dot net core, a next gen technology
Microservices with asp dot net core, a next gen technologyMicroservices with asp dot net core, a next gen technology
Microservices with asp dot net core, a next gen technology
 
Lecture 11 Firebase overview
Lecture 11 Firebase overviewLecture 11 Firebase overview
Lecture 11 Firebase overview
 

More from InnovationM

How to use data binding in android
How to use data binding in androidHow to use data binding in android
How to use data binding in androidInnovationM
 
Capture image on eye blink
Capture image on eye blinkCapture image on eye blink
Capture image on eye blinkInnovationM
 
How to use geolocation in react native apps
How to use geolocation in react native appsHow to use geolocation in react native apps
How to use geolocation in react native appsInnovationM
 
Android 8 behavior changes
Android 8 behavior changesAndroid 8 behavior changes
Android 8 behavior changesInnovationM
 
Understanding of react fiber architecture
Understanding of react fiber architectureUnderstanding of react fiber architecture
Understanding of react fiber architectureInnovationM
 
Automatic reference counting (arc) and memory management in swift
Automatic reference counting (arc) and memory management in swiftAutomatic reference counting (arc) and memory management in swift
Automatic reference counting (arc) and memory management in swiftInnovationM
 
Firebase crashlytics integration in iOS swift (dSYM File Required Problem Res...
Firebase crashlytics integration in iOS swift (dSYM File Required Problem Res...Firebase crashlytics integration in iOS swift (dSYM File Required Problem Res...
Firebase crashlytics integration in iOS swift (dSYM File Required Problem Res...InnovationM
 
How prototype works in java script?
How prototype works in java script?How prototype works in java script?
How prototype works in java script?InnovationM
 
React – Let’s “Hook” up
React – Let’s “Hook” upReact – Let’s “Hook” up
React – Let’s “Hook” upInnovationM
 
Razorpay Payment Gateway Integration In iOS Swift
Razorpay Payment Gateway Integration In iOS SwiftRazorpay Payment Gateway Integration In iOS Swift
Razorpay Payment Gateway Integration In iOS SwiftInnovationM
 
Paytm integration in swift
Paytm integration in swiftPaytm integration in swift
Paytm integration in swiftInnovationM
 
Line Messaging API Integration with Spring-Boot
Line Messaging API Integration with Spring-BootLine Messaging API Integration with Spring-Boot
Line Messaging API Integration with Spring-BootInnovationM
 
Basic fundamental of ReactJS
Basic fundamental of ReactJSBasic fundamental of ReactJS
Basic fundamental of ReactJSInnovationM
 
Basic Fundamental of Redux
Basic Fundamental of ReduxBasic Fundamental of Redux
Basic Fundamental of ReduxInnovationM
 
Integration of Highcharts with React ( JavaScript library )
Integration of Highcharts with React ( JavaScript library )Integration of Highcharts with React ( JavaScript library )
Integration of Highcharts with React ( JavaScript library )InnovationM
 
Serialization & De-serialization in Java
Serialization & De-serialization in JavaSerialization & De-serialization in Java
Serialization & De-serialization in JavaInnovationM
 
Concept of Stream API Java 1.8
Concept of Stream API Java 1.8Concept of Stream API Java 1.8
Concept of Stream API Java 1.8InnovationM
 
How to Make Each Round of Testing Count?
How to Make Each Round of Testing Count?How to Make Each Round of Testing Count?
How to Make Each Round of Testing Count?InnovationM
 
Model View Presenter For Android
Model View Presenter For AndroidModel View Presenter For Android
Model View Presenter For AndroidInnovationM
 

More from InnovationM (20)

How to use data binding in android
How to use data binding in androidHow to use data binding in android
How to use data binding in android
 
Capture image on eye blink
Capture image on eye blinkCapture image on eye blink
Capture image on eye blink
 
Mob x in react
Mob x in reactMob x in react
Mob x in react
 
How to use geolocation in react native apps
How to use geolocation in react native appsHow to use geolocation in react native apps
How to use geolocation in react native apps
 
Android 8 behavior changes
Android 8 behavior changesAndroid 8 behavior changes
Android 8 behavior changes
 
Understanding of react fiber architecture
Understanding of react fiber architectureUnderstanding of react fiber architecture
Understanding of react fiber architecture
 
Automatic reference counting (arc) and memory management in swift
Automatic reference counting (arc) and memory management in swiftAutomatic reference counting (arc) and memory management in swift
Automatic reference counting (arc) and memory management in swift
 
Firebase crashlytics integration in iOS swift (dSYM File Required Problem Res...
Firebase crashlytics integration in iOS swift (dSYM File Required Problem Res...Firebase crashlytics integration in iOS swift (dSYM File Required Problem Res...
Firebase crashlytics integration in iOS swift (dSYM File Required Problem Res...
 
How prototype works in java script?
How prototype works in java script?How prototype works in java script?
How prototype works in java script?
 
React – Let’s “Hook” up
React – Let’s “Hook” upReact – Let’s “Hook” up
React – Let’s “Hook” up
 
Razorpay Payment Gateway Integration In iOS Swift
Razorpay Payment Gateway Integration In iOS SwiftRazorpay Payment Gateway Integration In iOS Swift
Razorpay Payment Gateway Integration In iOS Swift
 
Paytm integration in swift
Paytm integration in swiftPaytm integration in swift
Paytm integration in swift
 
Line Messaging API Integration with Spring-Boot
Line Messaging API Integration with Spring-BootLine Messaging API Integration with Spring-Boot
Line Messaging API Integration with Spring-Boot
 
Basic fundamental of ReactJS
Basic fundamental of ReactJSBasic fundamental of ReactJS
Basic fundamental of ReactJS
 
Basic Fundamental of Redux
Basic Fundamental of ReduxBasic Fundamental of Redux
Basic Fundamental of Redux
 
Integration of Highcharts with React ( JavaScript library )
Integration of Highcharts with React ( JavaScript library )Integration of Highcharts with React ( JavaScript library )
Integration of Highcharts with React ( JavaScript library )
 
Serialization & De-serialization in Java
Serialization & De-serialization in JavaSerialization & De-serialization in Java
Serialization & De-serialization in Java
 
Concept of Stream API Java 1.8
Concept of Stream API Java 1.8Concept of Stream API Java 1.8
Concept of Stream API Java 1.8
 
How to Make Each Round of Testing Count?
How to Make Each Round of Testing Count?How to Make Each Round of Testing Count?
How to Make Each Round of Testing Count?
 
Model View Presenter For Android
Model View Presenter For AndroidModel View Presenter For Android
Model View Presenter For Android
 

Recently uploaded

Neelam 9058824046 Call Girls Service in Haridwar
Neelam 9058824046 Call Girls Service in HaridwarNeelam 9058824046 Call Girls Service in Haridwar
Neelam 9058824046 Call Girls Service in Haridwarjaanseema653
 
Call Girls in Chandigarh Annaya❤️🍑 9115573837 👄🫦Independent Escort Service Ch...
Call Girls in Chandigarh Annaya❤️🍑 9115573837 👄🫦Independent Escort Service Ch...Call Girls in Chandigarh Annaya❤️🍑 9115573837 👄🫦Independent Escort Service Ch...
Call Girls in Chandigarh Annaya❤️🍑 9115573837 👄🫦Independent Escort Service Ch...Niamh verma
 
KALENDAR KUDA 2024 Hi resolution cuti umum.pdf
KALENDAR KUDA 2024 Hi resolution cuti umum.pdfKALENDAR KUDA 2024 Hi resolution cuti umum.pdf
KALENDAR KUDA 2024 Hi resolution cuti umum.pdfSallamSulaiman
 
Jumeirah Call Girls Dubai Concupis O528786472 Dubai Call Girls In Bur Dubai N...
Jumeirah Call Girls Dubai Concupis O528786472 Dubai Call Girls In Bur Dubai N...Jumeirah Call Girls Dubai Concupis O528786472 Dubai Call Girls In Bur Dubai N...
Jumeirah Call Girls Dubai Concupis O528786472 Dubai Call Girls In Bur Dubai N...hf8803863
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Bhikaji Cama Palace | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Bhikaji Cama Palace | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Bhikaji Cama Palace | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Bhikaji Cama Palace | Delhisoniya singh
 
22K Indian Gold Jewelry Online - Buy 22 Karat Gold Jewelry in USA
22K Indian Gold Jewelry Online - Buy 22 Karat Gold Jewelry in USA22K Indian Gold Jewelry Online - Buy 22 Karat Gold Jewelry in USA
22K Indian Gold Jewelry Online - Buy 22 Karat Gold Jewelry in USAQueen of Hearts Jewelry
 
My Personal Testimony - James Eugene Barbush - March 11, 2024
My Personal Testimony - James Eugene Barbush - March 11, 2024My Personal Testimony - James Eugene Barbush - March 11, 2024
My Personal Testimony - James Eugene Barbush - March 11, 2024JAMES EUGENE BARBUSH
 
Moscow City People project Roman Kurganov
Moscow City People project Roman KurganovMoscow City People project Roman Kurganov
Moscow City People project Roman KurganovRomanKurganov
 
Call Numbe 9892124323, Vashi call girls, Juhu Call Girls, Powai Call Girls Se...
Call Numbe 9892124323, Vashi call girls, Juhu Call Girls, Powai Call Girls Se...Call Numbe 9892124323, Vashi call girls, Juhu Call Girls, Powai Call Girls Se...
Call Numbe 9892124323, Vashi call girls, Juhu Call Girls, Powai Call Girls Se...Pooja Nehwal
 
Sakshi 9058824046 Call Girls Service in Kanpur
Sakshi 9058824046 Call Girls Service in KanpurSakshi 9058824046 Call Girls Service in Kanpur
Sakshi 9058824046 Call Girls Service in Kanpurjaanseema653
 
Dubai Call Girls O528786472 Call Girls Dubai OL
Dubai Call Girls O528786472 Call Girls Dubai OLDubai Call Girls O528786472 Call Girls Dubai OL
Dubai Call Girls O528786472 Call Girls Dubai OLhf8803863
 
A TO Z INDIA Monthly Magazine - MAY 2024
A TO Z INDIA Monthly Magazine - MAY 2024A TO Z INDIA Monthly Magazine - MAY 2024
A TO Z INDIA Monthly Magazine - MAY 2024Indira Srivatsa
 
Call US 📞 9892124323 ✅ V.VIP Call Girls In Andheri ( Mumbai )
Call US 📞 9892124323 ✅ V.VIP Call Girls In Andheri ( Mumbai )Call US 📞 9892124323 ✅ V.VIP Call Girls In Andheri ( Mumbai )
Call US 📞 9892124323 ✅ V.VIP Call Girls In Andheri ( Mumbai )Pooja Nehwal
 
Call Girls {Delhi Meet Payal Pitampura} 9711199012 Indepedemt Girls Delhi
Call Girls {Delhi Meet Payal Pitampura} 9711199012 Indepedemt Girls DelhiCall Girls {Delhi Meet Payal Pitampura} 9711199012 Indepedemt Girls Delhi
Call Girls {Delhi Meet Payal Pitampura} 9711199012 Indepedemt Girls DelhiMs Riya
 
Independent Call Girls Delhi ~9711199012~ Call Me
Independent Call Girls Delhi ~9711199012~ Call MeIndependent Call Girls Delhi ~9711199012~ Call Me
Independent Call Girls Delhi ~9711199012~ Call MeMs Riya
 
Call Girls in Chittaranjan Park Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Chittaranjan Park Delhi 💯Call Us 🔝8264348440🔝Call Girls in Chittaranjan Park Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Chittaranjan Park Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Call Girls in Sarita Vihar__ 8448079011 Escort Service in Delhi
Call Girls in Sarita Vihar__ 8448079011 Escort Service in DelhiCall Girls in Sarita Vihar__ 8448079011 Escort Service in Delhi
Call Girls in Sarita Vihar__ 8448079011 Escort Service in DelhiRaviSingh594208
 
Call Girls in mahipalpur Delhi 8264348440 ✅ call girls ❤️
Call Girls in mahipalpur Delhi 8264348440 ✅ call girls ❤️Call Girls in mahipalpur Delhi 8264348440 ✅ call girls ❤️
Call Girls in mahipalpur Delhi 8264348440 ✅ call girls ❤️soniya singh
 

Recently uploaded (20)

Neelam 9058824046 Call Girls Service in Haridwar
Neelam 9058824046 Call Girls Service in HaridwarNeelam 9058824046 Call Girls Service in Haridwar
Neelam 9058824046 Call Girls Service in Haridwar
 
Hauz Khas Call Girls Delhi ✌️Independent Escort Service 💕 Hot Model's 9999965857
Hauz Khas Call Girls Delhi ✌️Independent Escort Service 💕 Hot Model's 9999965857Hauz Khas Call Girls Delhi ✌️Independent Escort Service 💕 Hot Model's 9999965857
Hauz Khas Call Girls Delhi ✌️Independent Escort Service 💕 Hot Model's 9999965857
 
Call Girls in Chandigarh Annaya❤️🍑 9115573837 👄🫦Independent Escort Service Ch...
Call Girls in Chandigarh Annaya❤️🍑 9115573837 👄🫦Independent Escort Service Ch...Call Girls in Chandigarh Annaya❤️🍑 9115573837 👄🫦Independent Escort Service Ch...
Call Girls in Chandigarh Annaya❤️🍑 9115573837 👄🫦Independent Escort Service Ch...
 
KALENDAR KUDA 2024 Hi resolution cuti umum.pdf
KALENDAR KUDA 2024 Hi resolution cuti umum.pdfKALENDAR KUDA 2024 Hi resolution cuti umum.pdf
KALENDAR KUDA 2024 Hi resolution cuti umum.pdf
 
Jumeirah Call Girls Dubai Concupis O528786472 Dubai Call Girls In Bur Dubai N...
Jumeirah Call Girls Dubai Concupis O528786472 Dubai Call Girls In Bur Dubai N...Jumeirah Call Girls Dubai Concupis O528786472 Dubai Call Girls In Bur Dubai N...
Jumeirah Call Girls Dubai Concupis O528786472 Dubai Call Girls In Bur Dubai N...
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Bhikaji Cama Palace | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Bhikaji Cama Palace | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Bhikaji Cama Palace | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Bhikaji Cama Palace | Delhi
 
22K Indian Gold Jewelry Online - Buy 22 Karat Gold Jewelry in USA
22K Indian Gold Jewelry Online - Buy 22 Karat Gold Jewelry in USA22K Indian Gold Jewelry Online - Buy 22 Karat Gold Jewelry in USA
22K Indian Gold Jewelry Online - Buy 22 Karat Gold Jewelry in USA
 
My Personal Testimony - James Eugene Barbush - March 11, 2024
My Personal Testimony - James Eugene Barbush - March 11, 2024My Personal Testimony - James Eugene Barbush - March 11, 2024
My Personal Testimony - James Eugene Barbush - March 11, 2024
 
Moscow City People project Roman Kurganov
Moscow City People project Roman KurganovMoscow City People project Roman Kurganov
Moscow City People project Roman Kurganov
 
Call Numbe 9892124323, Vashi call girls, Juhu Call Girls, Powai Call Girls Se...
Call Numbe 9892124323, Vashi call girls, Juhu Call Girls, Powai Call Girls Se...Call Numbe 9892124323, Vashi call girls, Juhu Call Girls, Powai Call Girls Se...
Call Numbe 9892124323, Vashi call girls, Juhu Call Girls, Powai Call Girls Se...
 
Sakshi 9058824046 Call Girls Service in Kanpur
Sakshi 9058824046 Call Girls Service in KanpurSakshi 9058824046 Call Girls Service in Kanpur
Sakshi 9058824046 Call Girls Service in Kanpur
 
Dubai Call Girls O528786472 Call Girls Dubai OL
Dubai Call Girls O528786472 Call Girls Dubai OLDubai Call Girls O528786472 Call Girls Dubai OL
Dubai Call Girls O528786472 Call Girls Dubai OL
 
A TO Z INDIA Monthly Magazine - MAY 2024
A TO Z INDIA Monthly Magazine - MAY 2024A TO Z INDIA Monthly Magazine - MAY 2024
A TO Z INDIA Monthly Magazine - MAY 2024
 
Gurgaon Call Girls 9953525677 Call Girls Low Rate.pdf
Gurgaon Call Girls 9953525677 Call Girls Low Rate.pdfGurgaon Call Girls 9953525677 Call Girls Low Rate.pdf
Gurgaon Call Girls 9953525677 Call Girls Low Rate.pdf
 
Call US 📞 9892124323 ✅ V.VIP Call Girls In Andheri ( Mumbai )
Call US 📞 9892124323 ✅ V.VIP Call Girls In Andheri ( Mumbai )Call US 📞 9892124323 ✅ V.VIP Call Girls In Andheri ( Mumbai )
Call US 📞 9892124323 ✅ V.VIP Call Girls In Andheri ( Mumbai )
 
Call Girls {Delhi Meet Payal Pitampura} 9711199012 Indepedemt Girls Delhi
Call Girls {Delhi Meet Payal Pitampura} 9711199012 Indepedemt Girls DelhiCall Girls {Delhi Meet Payal Pitampura} 9711199012 Indepedemt Girls Delhi
Call Girls {Delhi Meet Payal Pitampura} 9711199012 Indepedemt Girls Delhi
 
Independent Call Girls Delhi ~9711199012~ Call Me
Independent Call Girls Delhi ~9711199012~ Call MeIndependent Call Girls Delhi ~9711199012~ Call Me
Independent Call Girls Delhi ~9711199012~ Call Me
 
Call Girls in Chittaranjan Park Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Chittaranjan Park Delhi 💯Call Us 🔝8264348440🔝Call Girls in Chittaranjan Park Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Chittaranjan Park Delhi 💯Call Us 🔝8264348440🔝
 
Call Girls in Sarita Vihar__ 8448079011 Escort Service in Delhi
Call Girls in Sarita Vihar__ 8448079011 Escort Service in DelhiCall Girls in Sarita Vihar__ 8448079011 Escort Service in Delhi
Call Girls in Sarita Vihar__ 8448079011 Escort Service in Delhi
 
Call Girls in mahipalpur Delhi 8264348440 ✅ call girls ❤️
Call Girls in mahipalpur Delhi 8264348440 ✅ call girls ❤️Call Girls in mahipalpur Delhi 8264348440 ✅ call girls ❤️
Call Girls in mahipalpur Delhi 8264348440 ✅ call girls ❤️
 

Eventbus Library and How Does it Work?

  • 1. What is EventBus Library and How Does it Work? In this blog, we are going to discuss about the Eventbus library. What is EventBus: EventBus Is open Source android library that simplifies communication between Activities, Fragments, Threads, Services, with Less code, better quality.When we develop an android application we need to manage a lot of intercommunication between android components which some time's become very difficult to manage. Eventbus library makes this task easy to implement. Why EventBus? The main reason why we should use EventBus is loose coupling. Sometimes you want to process specific events that are interested for multiple parts of your application like presentation layer business layer and data layer so EventBus provides a easy solution for this. Some features of EventBus library: 1-Simple yet powerful: 2- Battle tested: 3-High Performance 4-Convenient Annotation based API 5-Event & Subscriber inheritance
  • 2. you need to have four thing for implement EventBus: 1- A EventBus Object . EventBus myEventBus = EventBus.getDefault(); 2- A Event normal pojo class. public class DataSyncEvent { private final String syncStatusMessage; public DataSyncEvent(String syncStatusMessage) { this.syncStatusMessage = syncStatusMessage; } public String getSyncStatusMessage() { return syncStatusMessage; } } 3- The sender which will send the event: EventBus.getDefault().post(new DataSyncEvent("Sync SuccessFully”); 4- The subscriber is someone who will listen to our event. @Subscribe public void onEvent(DataSyncEvent syncStatusMessage) { Toast.makeText(this, syncStatusMessage.getSyncStatusMessage(), Toast.LENGTH_SHORT).show(); } The last two step are Register and unregister the Eventbus who want to listen to the event. The best way is register in onStart method and unRegister in the onStop method of activity. @Override protected void onStart() { super.onStart(); EventBus.getDefault().register(this); } @Override protected void onStop() { super.onStop(); EventBus.getDefault().unregister(this);
  • 3. } Example of EventBus: Let's take a simple example, In our project, if we want to Sync our data to the server at the time of applicaiton launch, for this, simply start an intent service from the launcher activity of your application and through intent service sync the data to the server. After that notify the screen(Through EventBus library) which is currently visible to user about syncing. Implementation of EventBus: Add the dependencies in the gradle file. compile 'de.greenrobot:eventbus:2.4.0' Intent service class which will start at the time of application launch. public class SyncDataService extends IntentService { public SyncDataService() { super("SyncDataService"); } @Override protected void onHandleIntent(Intent intent) { //first check if internet is availabe or not. if(DeviceManager.isInternetAvailableOnDevice()) { // try // { // //write the code to sync the data to Server //post the event after sync complete EventBus.getDefault().post(new DataSyncEvent("Data Sync SuccessFully")); // } // catch (RTITBException exception) // { // LogManager.getInstance().addLog(exception.getExceptionCode(),exceptio n.getMessage(),exception); // } } }
  • 4. } The Maine Activity. public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } //Register the EventBus @Override protected void onStart() { super.onStart(); EventBus.getDefault().register(this); } //UnRegister the EventBus @Override protected void onStop() { super.onStop(); EventBus.getDefault().unregister(this); } //The Method which will call every time when data sync to server @Subscribe public void onEvent(DataSyncEvent syncStatusMessage) { //you can do whatever you want releted with UI Toast.makeText(this, syncStatusMessage.getMessage(), Toast.LENGTH_SHORT).show(); } } If any other component of you applicaiton want to listen to the event then only we need to register for the EventBus as mentioned in above method onStart and override the method onEvent. Conclusion: Eventbus library is just like a radio frequency, if you wish to listen to any song, you simply need to set the frequency to that station. Likewise, event bus library posts events, if any component wants to listen that event then we need to register that component for the EventBus object and we will get that event in onEvent Method.