I'm having a problem running an SQLite function in the onPostExecute method of AsyncTask. When implementing the same function in the Activity it executes normally, but onPostExecute does not even enter the breakpoint I put in the function.
The function that performs the user update is as follows:
public class UpdateDatabaseOff{
...
public static void updateUser(Context context, JSONObject object){
try{
User user;
user = new User(object);
Queries.setDataToDatabase(context, User.tableName, user);
}
catch(JSONException e){
e.printStackTrace();
}
}
}
The Queries class and the setDataToDatabase function are below:
public static Integer setDataToDatabase(Context context, String tableName, GenericsTable genericsTable){
long id = -1;
getDatabase(context).get().beginTransaction();
try {
if (genericsTable.getSingleCode() != null) {
int rowsUpdate = getDatabase(context).get().update(tableName, genericsTable.getContentValues(), genericsTable.getSingleCode(), null);
if (rowsUpdate == 0) {
id = getBanco(context).get().insert(tableName, null, genericsTable.getContentValues());
}else{
StringBuffer query = new StringBuffer();
query.append(" SELECT id FROM " + tableName);
query.append(" WHERE " + genericsTable.getSingleCode() );
final Cursor cursor = Queries.getSelect(context, query);
id = cursor.getLong(cursor.getColumnIndex("id"));
}
}else{
id = getBanco(context).get().insert(tableName, null, genericsTable.getContentValues());
}
getBanco(context).get().setTransactionSuccessful();
} finally {
getBanco(context).get().endTransaction();
}
return new Integer(String.valueOf(id));
}
Then, finally, I call the updateUser function in onPostExecute:
protected void onPostExecute(JsonReturn jsonReturn){
...
UpdateDatabaseOff.updateUser(context, jsonenvio); //Não funciona
}
I do not know what it can be. I tried putting the function on a Thread and nothing. Any help is welcome:)