Closed Chuckytuh closed 7 years ago
+1
I can confirm this BUG in version 0.6.4. Here is a sample code I used to test it. Sometimes if unregisterNdef() is called the java.util.ConcurrentModificationException is thrown, but not always. After app restart unregisterNdef() is working as expected. I can't reproduce it!
function register() {
ionic.Platform.ready(function () {
console.log("Register");
registerNdef();
});
}
function unregister() {
ionic.Platform.ready(function () {
console.log("Un-Register");
unregisterNdef();
});
}
function ndefCallback(nfcEvent) {
var tag = nfcEvent.tag,
ndefMessage = tag.ndefMessage;
// dump the raw json of the message
// note: real code will need to decode
// the payload from each record
alert(JSON.stringify(ndefMessage));
// assuming the first record in the message has
// a payload that can be converted to a string.
alert(nfc.bytesToString(ndefMessage[0].payload).substring(3));
}
function registerNdef() {
// Read NDEF formatted NFC Tags
nfc.addNdefListener(
ndefCallback,
function () { // success callback
console.log("Registered NDEF listener");
},
function (error) { // error callback
console.log("Error register NDEF listener " + JSON.stringify(error));
}
);
}
function unregisterNdef() {
nfc.removeNdefListener(
ndefCallback,
function () { // success callback
console.log("Unregistered NDEF listener");
alert("Waiting for NDEF tag");
},
function (error) { // error callback
console.log("Error unregister NDEF listener " + JSON.stringify(error));
}
);
}
@don please could you look over the PR, @Chuckytuh is right with his implementation, see: http://stackoverflow.com/questions/223918/iterating-through-a-collection-avoiding-concurrentmodificationexception-when-re
@didlich I'll review this soon
Calling remove() on the ArrayList while iterating over it throws java.util.ConcurrentModificationException.