0
I’m having a problem running an Sqlite function in the Asynctask onPostExecute method. When I implement the same function in Activity it runs normally, but in onPostExecute it doesn’t even enter the breakpoint I put in the function.
The function that performs the user update is the following:
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();
}
}
}
Queries class and 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 on onPostExecute:
protected void onPostExecute(JsonReturn jsonReturn){
...
UpdateDatabaseOff.updateUser(context, jsonenvio); //Não funciona
}
I don’t know what it could be. I tried to put the function in a Thread and nothing. Any help is welcome :)
marked the onPostExecute method with @override?
– Geferson
I marked @Geferson, thanks for the answer. I solved the problem, I will answer my question to close.
– Bruno Pardini