My question exceeds the limitations of the title, so I'll elaborate here. I am developing an app that can write and read a NDEF message on/from NFC cards when detected by a phone. The issue is that everything in the code seems to repeat itself four times.
Although "UltraLightCard Detected" and "Connected" messages only appear once, everything else within the code, including the AlertDialog box, pops up 4 times, requiring users to input text 4 times even if they only want to save it once.
Below is a snippet of my code:
protected void ultralightCardLogic() {
final Button b_write = (Button)findViewById(R.id.b_write);
final Button b_read = (Button)findViewById(R.id.b_read);
b_write.setId(1);
b_read.setId(2);
ShowMessage("UltraLight Card Detected :" + mifareUL.getTagName(), 'a');
try {
mifareUL.connect();
mifareUL.formatT2T();
ShowMessage("Connected!" , 'd');
b_write.setOnTouchListener(new MyTouchListener());
b_read.setOnTouchListener(new MyTouchListener());
} catch (IOException e) {
e.printStackTrace();
}
}
If you require more code snippets for further assistance, please let me know. Any help is greatly appreciated.