Welcome Android Developpers

Welcome Android Developpers
My name is Mathias Séguy, I am an Android Expert and Trainer and created the Android2EE company.

For full information, it’s here : Android2EE's Training
You can meet me on Google+, follow me on Twitter or on LinkedIn

Thursday, December 15, 2011

Handlers, Threads and Activity's life cycle

Bandeau Conference
Hello,
As I said earlier, when managing Handlers or AsynchTasks, you must always make sure to link the life cycle of the thread with the Handler's one which is also linked with the activity's one ... Otherwise, your thread becomes an orphan Thread.
Ok, digging a little bit more (I will drop you on Androi2EE an eclipse project that shows what I'm saying) it's worse, in fact: When passing by OnDestroy and onCreate (short I return the device), not only the thread becomes orphan, but also the Handler (arg, what it is not destroyed o_O ') and worse is that your activity becomes a ghost ... glooops.
And yes it's crazy, the first activity is not destroyed, she is called by the first thread through the first Handler (hence the absence of the raise of a NullPointer exception) and the second activity is created with the new Handler and its new Thread.

I mean, DarkVador, Voldemor and Sauron laughed thinking of the number of threads, Handlers, AsynchTask, and activities ghosts that inhabit the Android devices because developers unaware of the danger.

So: Manage your threads by linking their life cycle with that of the activity.
So, Thanks who?
Thanks, Android2ee, the Android Programming Ebooks :o)

Mathias Séguy
mathias.seguy.it@gmail.com
Auteur Android2EE
Ebooks to learn Android Programming.
AndroidEvolution
Retrouvez moi sur Google+
Suivez moi sur Twitter
Rejoignez mon réseau LinkedIn ou Viadeo

No comments:

Post a Comment