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...
This library having good implementation for Android developer who don't won't spoil time written for initialize the Components, Resources, and so on. As I know those who want only like to written minimum code and output will be more. So use this library. Guide means make development and debugging the code very easy and faster. With the help of RoboGuice library you should be able to understand your code very speedily with minimum time.
What is RoboGuice?
RoboGuice is a dependency injection framework for Android applications. RoboGuice is a framework that brings the simplicity and ease of Dependency Injection to Android.
RoboGuice 2 takes the guesswork out of development.Using RoboGuice, you can inject your View, Resource, System Service, or any other object.To express a dependency, you use annotations like Inject.
Usage of RoboGuice library:
- Views Injection: To initialize views - use @InjectViews, for example: @InjectView(R.id.txtName) TextView txtName;
- Resources Injection: To initialize and get resources, use @InjectResources, for example: @InjectResource(R.string.first_name) String name;
- System services Injection: To initialize and access system services, use @Inject, for example: @Inject LayoutInflater inflater;
- POJO object Injection: To inject and initialize POJO object, use @Inject, for example: @Inject Foo foo;
Installation of RoboGuice
The Installation of RoboGuice requires that you download the following JAR files and add them to your classpath.
Let's we look at typical Android activity example code:
After appliying RoboGuice Library with below code changes(Remove initialize lines)
Now we are going to through step by step to understand how to implement the basic things.
A. First inherits class with RoboActivity.
B. set content view to our Activity.
C. Now annotate our view with @InjectView
Assuming that we create one layout(R.layout.activity_demo) that contains one textview with id txtName, Now we inject that view Roboguice @InjectView. It looks like given code without having to call findViewById().
Let's take a full example with the help of RoboGuice Library.
1. Create Layout for MainActivity. activity_main.xml
2. Create Activity with roboguice injection.
3. Add JAR file into libs folder of project file.
4. Now you can run your project. Enjoy!!!!
You can download full source code from here.
RoboGuice Example
Reference Sites:
- https://code.google.com/p/roboguice/wiki/SimpleExample
- https://github.com/roboguice/roboguice
- http://code.google.com/p/roboguice/wiki/ProvidedInjections#RoboGuice_Standard_Injections
If you are satisfied with this post then please give your comments.
Thanks for your Interest!!!
Comments
Post a Comment