Android system webview



[music playing] colt mcanlis: so youknow what screams out, "this app is slow?" a spinner, especiallyone that sits around mocking the userwhile the activity behind it


Android system webview, is trying to load some ui data. my name is coltmcanlis, and this is one of the most annoyingui patterns on android. and believe it or not, it'sactually really easy to fix.


see, it's 2015 now, andmost modern applications drive the entiretyof their ui based upon information they grabfrom some server resource. and that's prettystraightforward. ping the server for updateddata, and once you get it, update your ui toreflect the changes. pretty simple, right? the problem hereis in what the user is seeing while they're waitingfor you to fetch the updated


information. and sure, if user'sbeen using the app, then chances are the screen isalready populated with data. but when you're respondingto a gnarly context change or are loading the app forthe first time in a while, there's no data topre-populate your view, so you have to defaultto a spinner on top of a blank screen. now, the fix here isreally straightforward.


caching. see, at some pointin the past, you've actually grabbed a validblock of ui information, except on your firstload, of course. but anyhow, althoughthe data is outdated, your app can use thatinformation in these situations where the fresh datahasn't been fetched yet. see, it works like this. upon a successfulfetch of some ui data,


serialize it to apersistent storage alongside sometimestamp so you know how old the information is. when you find yourselfin a cold boot situation, you can use the existing uidata to start drawing the screen while also kickingoff your server commands to grab thefreshest information. sure, you'll stillneed to flag the user and say what new informationis being fetched.


but at least they're lookingat a legitimate screen instead of a blank ui with somecrummy spinner on it, right? and that's reallypretty much it. cache your ui data sothat you can use it later when you need towait for the server to give you some updates. pretty straightforward,actually. uh-- oh!


by the way, it'sworth pointing out that there's a right and a wrongway to store this data to disk. firstly, you should be usinga binary serialization format since they producesmaller file sizes and have faster performancethan human-readable formats like json or xml. secondly, take thetime to figure out the best way to cache thisinformation persistently. just storing it tothe serialized blob


is one way of doing this. however, if your ui is dependenton a lot of complicated queries across that data,unserializing that to load it may not be thebest idea compared to storing it in a sqlitedatabase, which could be a much faster solution. but really, any ofthese options is better than showing a blankscreen with some spinner on it. even if you're thefastest app on the planet,


this will feel incrediblyslow to your users. and user perception iswhat it's all about, which is why should check out therest of the "android performance patterns" videos.


Android system webview

and don't forget to join ourgoogle+ community to ask other questions as well. so keep calm, profile yourcode, and always remember, perf matters.


Android system webview Rating: 4.5 Diposkan Oleh: PaduWaras