Skip to content

Instantly share code, notes, and snippets.

@leandrovianna
Last active August 29, 2015 14:10
Show Gist options
  • Save leandrovianna/05c8215559fb18901529 to your computer and use it in GitHub Desktop.
Save leandrovianna/05c8215559fb18901529 to your computer and use it in GitHub Desktop.
Transaction in Android (using SQLite)
db.beginTransaction(); //inicia a transação
try {
//operações de bancos são feitas aqui
//db.insert...
//caso o fluxo chegue aqui a transacao nao teve erros
//entao fazemos o commit da transacao
db.setTransactionSuccessful();
} catch (Exception e) {
//Um exceção foi disparada por alguma operação do banco
Log.e("Transaction", "ERRO: Transacao mal sucedida");
} finally {
//independente se a transação teve commit ou não, é necessário terminá-la.
db.endTransaction();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment