Android FileObserver finds SQLites, but not their tables/content -


i'm running problem using fileobserver update meta-database when new sqlites added specific directory on sd card. if manually adb push new sqlite directory, call onevent(fileobserver.create, <filename>), works perfectly. however, when call fileobserver.startwatching() , adb push new sqlite observer catch on own, calls onevent (with same params when call manually - checked), opens sqlite file fine, fails find of tables when query newly opened sqlite , throws sqlite exception.

i'm using sqlitedatabase's opendatabase() method, it's not failing find original , creating empty 1 (a common problem). additionally, same sqlite query made in adb shell accesses newly added sqlite's tables fine.

does have ideas why might happen? code seems work fine based on success of manual call, i'm looking quirks fileobservers or sqlite on android might have missed, i'm new both.

update: further debugging shows if adb push file , call onevent(fileobserver.create, <filename>) manually, start fileobserver watching , adb push same file same location, fileobserver executes onevent queries no trouble locating tables... not sure means.

i figured out problem - android's fileobserver's onevent method, file creation event, executes after creation of file, not waiting file finish being written. running race condition onevent method attempting query database before file had finished being written. when adb pushed , called onevent manually, there enough time file written, why worked then.

the quick fix me call queries in onevent parameter fileobserver.close_write instead of create. since i'm working read-only access these databases, time written first time, , close_write event won't triggered until done , ready queried.


Comments