i have basic program testing firebase. have 2 buttons: first writing firebase database "a", second writing "b" , checking them service:
myref.addvalueeventlistener(new valueeventlistener() { @override public void ondatachange(datasnapshot datasnapshot) { string value = datasnapshot.getvalue(string.class); if(value=="a") { tonegenerator tonegenerator= new tonegenerator(audiomanager.stream_dtmf,tonegenerator.max_volume); //this play tone 2 seconds. tonegenerator.starttone(tonegenerator.tone_dtmf_1, 500); try { thread.sleep(1000); } catch (interruptedexception e) { e.printstacktrace(); } tonegenerator.starttone(tonegenerator.tone_dtmf_1, 500); } if(value=="b") { tonegenerator tonegeneratora= new tonegenerator(audiomanager.stream_dtmf,tonegenerator.max_volume); //this play tone 2 seconds. tonegeneratora.starttone(tonegenerator.tone_dtmf_3, 500); try { thread.sleep(1000); } catch (interruptedexception e) { e.printstacktrace(); } tonegeneratora.starttone(tonegenerator.tone_dtmf_3, 500); }
the problem is, have no internet connection, mean can't write firebase database or b when click buttons, ondatachanged
function still triggered. want when database data changed.
update : when changed database manually ondatachange
still not triggered.its working once while program starting.
use childeventlistener
can put code want execute inside onchildchanged()
method.
Comments
Post a Comment