Threading and Loaders. (Android Performance Patterns Season 5, Ep. 8)

Threading and Loaders. (Android Performance Patterns Season 5, Ep. 8) - Hello friends Android tutorial and tips trik, The article you are reading this time with the title Threading and Loaders. (Android Performance Patterns Season 5, Ep. 8), we have prepared this article for you to read and download the information therein. hopefully fill posts article 5, article 8), article and, article android, article Ep., article Loaders., article Patterns, article Performance, article Season, article Threading, article Tutorial, we can write this you understand. Well, happy reading.

Title : Threading and Loaders. (Android Performance Patterns Season 5, Ep. 8)
link : Threading and Loaders. (Android Performance Patterns Season 5, Ep. 8)

Baca juga


Threading and Loaders. (Android Performance Patterns Season 5, Ep. 8)

[MUSIC PLAYING] What do we do withthreaded work when the activity that kickedit off is no longer alive? I'm Doug Stevenson, andthis is the exact issue solved by loaders.

By now, you've seen thatactivities in your application can be created anddestroyed at any time, either in response to theuser or because Android needed the resources.

This poses a problemfor your threaded work since the work may extend beyondthe lifetime of the activity.

Say you have a threadchugging away at some work and that thread holdsreferences to views that will update upon completion.

If the activity ends beforethe work is complete, a few things will happen.

First, because the strongreferences to the views, the activity objectwill be kept in memory until the work finally finishes.

This is a memoryleak, and we don't have to tell youthis is bad since it can cause your app to run outof memory and eventually crash.

Second, the lateupdates to these views are wasted becausethey're no longer visible.

And third, you mighthave to repeat the work for a whole new set of views.

To get your threadedwork to correctly cope with the activity lifecycleand avoid these problems, you should use loaders.

Loaders are wise to the innerworkings of the activity lifecycle, so you canensure your work ends in the right place every time.

A properly implemented loaderis resistant to activity leaks, always updatesthe correct views, and is never repeatedunnecessarily.

Let's take a lookat how this works.

Instead of kicking offyour work in an async task or some otherthread you control, you ask the activity for aninstance of a loader manager.

Send the work tothe loader manager and it will make sure that yourwork may be handled properly in the face of configurationchanges for the activity.

The loader manager alsocaches the work results so that it won't be repeatedwith future changes.

Now, what if an activitywith an active loader is being popped of thestack, never to return? What happens tothis in-flight work? In this case, the loadermanager makes a callback into your code, saying thatits results will never be used.

You can use this callbackto abort the work, clean up, and move on withoutwasting any more resources.

Now, it's worthnoting that loaders are specific toactivities, and as such, give you a solid frameworkfor separating your views from your worker threads andminimize the amount of work you would otherwise haveto repeat with the activity lifecycle.

The downside ofloaders is that can be quite a bit of extracode to get them correctly integrated into your app.

So to help youget started, we've provided some sample codeillustrating some common use cases.

And for more information onimproving your application performance, keep watching theAndroid Performance Patterns videos.

And don't forget to join the G+community for advice from other great engineers.

So keep calm, profile yourcode, and always remember, #perfmatters.

[MUSIC PLAYING].



Thus Article Threading and Loaders. (Android Performance Patterns Season 5, Ep. 8)

That article Threading and Loaders. (Android Performance Patterns Season 5, Ep. 8) This time, hopefully we can give you all of the benefits. Well, I'll see you in another article post.

You now read the article Threading and Loaders. (Android Performance Patterns Season 5, Ep. 8) the link address http://svedda79.blogspot.com/2016/08/threading-and-loaders-android.html

0 Response to "Threading and Loaders. (Android Performance Patterns Season 5, Ep. 8)"

Post a Comment