Page 1 of 1

problem with garbage collection [SOLVED]

Posted: Mon Aug 01, 2016 12:19 pm
by dorche
when work with serial port, after "GC_CONCURRENT" in logcat,
file descriptor "FileImputStream" is "-1 and error " read failed: EBADF (Bad file number)"
why? how to solve it?

Re: problem with garbage collection

Posted: Tue Aug 02, 2016 5:09 am
by dorche
hey guys, solved...
this method get you a file descriptor >> "int fd = HardwareControler.openSerialPort(......);"
after that create ParcelFileDescriptor >> "pfd = ParcelFileDescriptor.fromFd(fd);"
and then create FileInputStream >> "FileInputStream mFileInputStream = new FileInputStream(pfd.getFileDescriptor());"

Note: if "ParcelFileDescriptor" is in method scope after garbage collection, file descriptor of FileInputStream change to "-1"
then "ParcelFileDescriptor" must in class scope.