android - Firebase Listener freezes app ui -


my app implements childeventlistener load data arraylist (approximately 7000 items). during childadded execution each item, interface freezes , can not used. there way run in background , not impair usability? i've tried using asynctask , thread app freezes anyway. in advance.

class fbtask extends asynctas {

@override protected boolean doinbackground(final boolean... params){     int size = 7000; //aprox,     final arraylist<model> aux = new arraylist<>();     query db = firebasedatabase.getinstance().getreference()             .child("list").orderbychild("double");     childeventlistener cel = new childeventlistener() {         @override         public void onchildadded(datasnapshot datasnapshot, string s) {             model x = datasnapshot.getvalue(model.class);             if(x.gett()!=null) {                 aux.add(x)                 log.i("onchildadded", x.getid() + " added, pos: " + dx.size());                 if(aux.size()>=size) {                     data = aux;                 }             }         }          @override         public void onchildchanged(datasnapshot datasnapshot, string s) {          }          @override         public void onchildremoved(datasnapshot datasnapshot) {          }          @override         public void onchildmoved(datasnapshot datasnapshot, string s) {          }          @override         public void oncancelled(databaseerror databaseerror) {          }     };     db.addchildeventlistener(cel); }  @override protected void onprogressupdate(boolean... values) {  }  @override protected void onpreexecute() {  }  @override protected void onpostexecute(downadapter result) {     if(result != null) {         downactivity.downrecview.setadapter(result);     } }  @override protected void oncancelled() {  } 

}

all network interaction , other work firebase client happens off main thread. things happens on main thread callbacks code, such onchildadded(). done can update ui code.

my guess calling datasnapshot.getvalue(model.class) 7000 times taking times, causing frames skipped. need 7000 models? i'd recommend retrieve data you're going show directly user, , 7000 models sounds more reasonably fit on screen android devices.

if must retrieve , decode many items, need use asynctask or background service. if you're having trouble making work, share minimal code reproduces got stuck.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -