android - Loading data effectively in RecycleView -
i'm populating list of data , data loaded in 3 steps, after first step finsihed show data user. update ui step step whenever data loading state changes...
i use recyclerview
display data. observe, when loading of single steps fast, ui blocking (especially when user scrolling fast)... need group events , update ui every x ms...
with testing saw, updating ui every 150ms seems , fast , not lead visible stuttering.
but i'm not sure how older devices or other devices react.
does have experience in direction , can tell me value good?
general question
probably question can asked more generally: when updating ui frequently, what's best frequence use avoid blocking ui? or what's minimum time wait before updating ui again
your question interesting , there methods solving. put solutions here reference.
1. cache data
when user scroll, adapter query data array, database or network. due slow performance, guess maybe problem because long loading data time. best method solving problem caching data.
you can cache data on memory using lrucache class , on disk using disklrucache there android guideline problem: caching bitmap
psuedo code:
if (memorycache.get(key)) { // load data memory , assign cell } else if (diskcache.get(key)) { // load data disk , assign cell } else { // data database or network // assign cell // save memory cache // save disk cache }
2. use different thread loading data
when process long running task affect ui, should put off ui thread , create new thread purpose. can use asynctask purpose.
the problem in method is: while loading data background, displayed cell on screen scroll event need different data. so, when old asynctask object finished work, assigns old data cell. bump!!!. must control cell's state carefully. there nice tutorial: process image loading in different thread
3. simplify view
if don't use such database handling, network request while scrolling, maybe problem view complex. should use tool:hierarchy viewer checking layout file has performance problem. can use tool gpu overdraw tool checking if many parts on view has drawn many thing unnecessary.
4. detect time updating data base on frame rate
you must keep frame rate below 60fps. frame rate, user not recognize lag, clunky ... in view. can use gpu profiler checking frame rate. base on frame rate, decide should simplify view, optimize ondraw
method or optimize gpu drawing (due overdrawing) keeping ui frame rate <= 60fps.
all above methods have integrated project named imageuploader . application uploads image flickr service , display list of uploaded images or view single images.
google has uploaded series of android performance pattern teach many useful things such caching, batching, useful tips ...
hope :)
Comments
Post a Comment