Skip to main content

Posts

Showing posts from August, 2013

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

DatabaseLocked Exception in SQLite : Android

Many time we face this error due to multiple times we access the tables (Same table or may be different table). Although I understand the which problem occur during this single database accessing multiple tables same time. I face this kind of problem many times. Means when I was inserting some value to local database at that same time I was fetching some value to send data on server in background. This problem arise occasionally when we use AsyncTasks or else with thread, because of database - access the tables and its data in a fraction of second. Database trying to access the tables and same time user hit second request so database again access to other table. So this issue was arise. But, here I try to overcome this problem using synchronized the accessing database. Let me give you one be one steps with description. SQLDataSQLHelper.java     This getInstance method will call only when mInstance is null. So its called only once when we start our application. After

Passing ArrayList from one activity to other

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. If you are satisfied then please give your comments. Thanks for your Interest!!!

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 Part - 1 : Calling Web Service from Android 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 Andro

Part - 1 : Calling Web Service from Android

I was running Web Service successfully in Year-2010 and already post into many forums. But some of forum/sites had removed that post So I thought to post once again for those who still facing problem. First I am giving simple code that will help you. First create Dynamic Web project using Eclipse IDE. and create one class : Converter.java This class place under this package:  org.web.prashant.adesara now select Converter.java file and do right click and New--> Other--> Web Services--> and select Web Service There are two option 1. Web Service Type 2. Client Type in first point you have to select slider as a Start Service: and in second point you have to select slider as a Test Client and click on Finish button. You web Service will run automatically. Just check your webservice will work properly or not. Main Steps: Now most important thing is you have to download ksoap2 jar file Now Create Android Project and copy paste this code

Auto Turn Off/On GPS in Android

I was doing search from the net. There are multiple scenario to make application feature to enable/disable the GPS through Programming. If we want to track our children status where he/she going from School/college to any other place. So at that we can start GPS without notify them. Second scenario may be happen when our device is stolen or lost at any place and someone open our application or restart the device so automatic start our application and send data to our server. That also be happen. But this is not fully reliable that we get back our device. At lease we know the location where our device is Below code is used for enable/disable the GPS using Android by Programming. 1. Forcefully Enable the GPS if its disable 2. Forcefully Disable the GPS if its Enable [Auto Enable/Disable GPS Programmatically] If you are satisfied then please give your comments. Thanks for your Interest!!!