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...
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 through out application we can use older initiated mInstance.
SQLOperation.java
This operation called many times whenever we want to open activity or need to access database. That is based on our requirement.
And then sqlHelper is used for writing and reading tables from database.
UserActivity.java
Here we can perform different operation like Add, update and delete from tables using SQLOperation.
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 through out application we can use older initiated mInstance.
SQLOperation.java
This operation called many times whenever we want to open activity or need to access database. That is based on our requirement.
And then sqlHelper is used for writing and reading tables from database.
UserActivity.java
Here we can perform different operation like Add, update and delete from tables using SQLOperation.
You can also download full example from here.
DatabaseLockedDemo : https://github.com/prashantadesara/DatabaseLockedDemo
Hey.. Thanks For this Direction.
ReplyDeleteThanks a Lot.
Thanks for your interest in my blogs!
DeleteITs My Pleasure..
Delete