Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Ektorp Android - NetworkOnMainThreadException from ChangesFeedAsyncTask #86

pramodchakrapani opened this Issue Jun 10, 2012 · 0 comments


None yet
1 participant

On android, creating a CouchDbConnector on UI thread throws a NetworkOnMainThreadException error while the device is running in StrictMode(android treats this as a network call). So, it has to be created in a background thread.

Currently, the ChangesFeedAsyncTask class takes a CouchDbConnector as one of the Constructor argument and because AsyncTasks are instantiated from UI thread, the CouchDBConnector has to be first obtained in a background thread and then be used for instantiating ChangesFeedAsyncTask. Instead of letting applications spawn a separate thread just for creating a connector, it would be easier if the ChangesFeedAsyncTask is changed as :

 * Create a ChangesFeedAsynTask with ChangesCommand 
 * @param changesCommand the changeCommand to execute 
public ChangesFeedAsyncTask(ChangesCommand changesCommand) { 
this.changesCommand = changesCommand; 


protected Object doInBackground(Void... params) { 
 Object result = null; 
 couchDbConnector = getCouchDbConnector(); 
 changesFeed = couchDbConnector.changesFeed(changesCommand); 

 // override this method to return a CouchDbConnector 
protected abstract CouchDbConnector getCouchDbConnector(); 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment