Skip to main content

Introduction and Example of Eventbus in Android.

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

Part - 2: Webservice running in Android with Database


If you do not completed simple example for how to call soap service from android then please look at my

After successfully understand the basic info from Part - 1, we moved to another advance example with database connectivity. Our android application connected with database, return value and display in our Android device.

Here, I am using Microsoft SQL Server Database connectivity, you can use your preferred database.

Before start the our implementation we first download the required library files for our use.

1. SQL Connectivity jar file for Webservice : http://www.4shared.com/file/IxoPooiE/sqljdbc.html
2. Ksoap Library file for Android : http://www.4shared.com/file/uOhx5aoj/ksoap2-android-assembly-24-jar.html

Dynamic Web Project

First we create webservice project. In that project we are connecting SQL database and write connection between them to retrieve the books data. Once its completed then move to Android application.

1. Create Dynamic Project using your IDE (Eclipse)

2. BookData.java (Bean/Model).

3. Add SQL.jar file to lib folder.

4. GetDatabaseRecords.java

5. Now Right click on GetDatabaseRecords.java file and select "WebService" option. Now further step is same as my Post Part 1:

6. Click finish.

Here the Dynamic Webservice Project part is completed. I hope you do not have any question till now.


Android Application

1. Create Android Application which calling above our webservice part.

2. Add Ksoap.jar Library into Android application

3. MainActivity.java

4. Now run your Android project and it will display book details on your device.

 Please leave your comment/query here, if you still facing any problem.


Comments

  1. Brother, I am stuck somewhere in calling the webservices from Android device. I have searched so many blogs but did not get any satisfactory solution. Can you please help. I need to display the array values in my webservice to my android device. The webservice call from android confusing me. How to display the whole list values from Webservice to android. If you reply i will send the complete code of android. Thanks

    ReplyDelete

Post a Comment

Popular posts from this blog

Android Client Connected with Socket Server

I hope this will help you for how to start communication between Socket Server (Desktop Chat Server Application) and Mobile Application (Android Socket Client). This application simply look like as chat application. You can add your idea and innovation to make very useful application. Follow below steps to run application: Use custom port and define same port in both application (i.e. Port No: 5657 ) Define computer IP Address in Android Client Application. (i.e. 192.168.1.x) . If you want to run this application in real device, then you can't connect with Desktop Socket Server. For that you need to upload runnable jar file in specific server and then you can use that server IP Address. First start Socket Server Application using Start button. Now you can start Android application. Just Enjoy it !!! Here I give you screen shot for communication between both application. [Socket Server (Desktop Application)] [Socket Client (Android Application)]

Disable Force Stop in Android

I have worked since 1 week on how to disable the FORCE STOP button in Manage Application in Android. And I was able to disable the Force Stop and Uninstall button in Manage Application. For that you need to make your application as Device Administrator. Android has add this kind of feature from Android 2.2 version. This feature is for Security reason with different option. Set Minimum Password Strength, Data Wipe, Force Lock,  Reset Password and so on. We set our application as Device Administrator to change above features. For more info and advance example you can check your android-sdk path (>= android-8). \samples\android-[>=8]\ApiDemos\src\com\example\android\apis\app\DeviceAdminSample.java See the below screen shots which shows how to activate the application and disable force stop button. [Active device adminstrator] [Disable the Force Stop and Uninstall button] Follow the below steps to disable the FORCE STOP button. 1. Create one cl

Introduction and Example of Eventbus in Android.

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