Firebase doesn't send data ordered in my case -


i have ordered data in firebase. order critical me. firebase can't send ordered in case. (ps: persistence enabled. tried @ android , ios client. result same.)

first, there 3 items , received them.

cache: 1,2,3      firebase:1,2,3 

then, closed app , updated data(inserted 3 item).

cache: 1,2,3      firebase:1,2,3,4,5,6 

i opened app , limittolast(1) method last item.

cache: 1,2,3,6    firebase:1,2,3,4,5,6 

and error coming..

i registered node childadded event. childadded callback triggered sequence:

1,2,3,6,4,5 

i don't want sort items. should do?

i finished example project. https://github.com/muzafferyilmaz/firebaseordertesting

update

relevant code snippet linked github project:

private childeventlistener mchildeventlistener = new childeventlistener() {     @override     public void onchildadded(datasnapshot datasnapshot, string s) {         string text = datasnapshot.getvalue(string.class);         log.i(tag, "onchildadded: " + text);         madapter.adddata(text);     } 

your problems caused fact you're ignoring second argument passed onchildadded:

void onchildadded(datasnapshot snapshot, string previouschildname) 

that previouschildname key of element new child needs added after. ignoring it, you're losing guarantee of ordering.

private childeventlistener mchildeventlistener = new childeventlistener() {     @override     public void onchildadded(datasnapshot datasnapshot, string s) {         string text = datasnapshot.getvalue(string.class);         log.i(tag, "onchildadded: " + text +  " after s");         madapter.adddata(text);     } 

logcat shows:

onchildadded: 1 after null onchildadded: 2 after onchildadded: 3 after b onchildadded: 6 after c onchildadded: 4 after c onchildadded: 5 after d 

if execute these in order, get:

  • a: 1
  • a: 1, b: 2
  • a: 1, b: 2, c: 3
  • a: 1, b: 2, c: 3, f: 6
  • a: 1, b: 2, c: 3, d: 4, f:6
  • a: 1, b: 2, c: 3, d: 4, e: 5, f:6

Comments

Popular posts from this blog

Capture and play voice with Asterisk ARI -

c++ - Can not find the "fiostream.h" file -

java - Why database contraints in HSQLDB are only checked during a commit when using transactions in Hibernate? -