My application is getting stuck while performing database operation after googling for solutions it was suggested that I use AsyncTask so that main thread doesn\'t get block
In your Actvity
add the following code, do the required changes,
private class GetContacts extends AsyncTask<Object, Object, Cursor> {
DatabaseConnector dbConnector = new DatabaseConnector(
getApplicationContext());
@Override
protected Cursor doInBackground(Object... params) {
dbConnector.open();
if (dbConnector.getAllValues() != null) {
return dbConnector.getAllValues();
} else
return null;
}
@Override
protected void onPostExecute(Cursor result) {
if (result != null) {
conAdapter.changeCursor(result); // set the adapter's Cursor
dbConnector.close();
}
}
}
execute this by new GetContacts().execute((Object[]) null);
No, you can't extend a class from multiple classes as it violates the property of java because java doesn't support multiple inheritence so for your case you have to create a new class which will extend ASyncTask and override the abstract methods to perform all the database related operations. Thank you