When a user taps their NFC tag, my app:
- Inserts a new user into the
users
table, getting back the user_id
, then - Writes this
_id
value to the user's NFC tag.
The problem is that if that user moves their tag away too quickly, step 2 will fail with an IOException
. The user will then have to tap their tag again, but this will result in step 1 being repeated - i.e., duplicate entries. :-/
To overcome this issue, I would like to use transactions based on this example code from the API documentation:
db.beginTransaction();
try {
// Insert data into database, getting back _id
// Write _id to NFC tag
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
...but my database is wrapped in a MyContentProvider
, so I don't have access to db
.
Is there a way to use transactions when inserting data without abandoning the usage of the MyContentProvider
?
Aucun commentaire:
Enregistrer un commentaire