Android2EE

  • Adapté
  • Large
  • Etroit
  • Increase font size
  • Default font size
  • Decrease font size
Prochaines formations Android inter-entreprises par Android2EE

Inscrivez-vous.

Inscrivez-vous dès maintenant.
N'attendez pas que les formations soient remplies (8 places maximum).

par mail : contact@android2ee.com ou

par téléphone 06 50 48 24 93. 
Du 24 au 28 Juin
Du 23 au 27 Sept.
Du 18 au 22 Nov. 
Paris  Formation Init.: Des fondamentaux à l'autonomie et la performance (3j)
Formation complète: Fondamentaux, Architecture et Android 4 (5j) 
Du 07 au 11 Oct.  Lyon Formation Init.: Des fondamentaux à l'autonomie et la performance (3j)
Formation complète : Fondamentaux, Architecture et Android 4 (5j) 
Du 16 au 20 Sept.
Du 25 au 29 Nov.
 

Toulouse
Formation Init.: Des fondamentaux à l'autonomie et la performance (3j)
Formation complète : Fondamentaux, Architecture et Android 4 (5j) 
La conférence "Android a Quick Course" est disponible, n'hésitez pas à la visionner. ici

Participez aux formations Android2EE et gagnez peut-être le Nexus (plus d'informations)

Lancement dès Octobre 2013 de la fromation Android 4+ dédiée à HoneyComb, IceCreamSandwich et JellyBean. Stay Tuned

Handlers and LifeCycle

E-mail Print PDF
You can find three tutorials explaining how to use the Handlers and specialy how to avoid memory leaks by linking the life cycle of your thread with your activity's one. Indeed, if you are not careful, when your activity is destroyed (by passing the method OnDestroy) your thread is not ... It became an orphan, you can not communicate with it. Worse, it points to your Handler that is related to the activity. Thus the garbage collector detects that these three objects are still "used" and do not garbage collector them. And there is the memory leak. Like everyone else, you used to declare your handler, your thread without linking them to the life cycle of your activity. And there is the drama. There are two ways to avoid this end of the world:
  • Either you implement booleans that can pause and then destroy the thread when your activity go throught the OnPause and OnDestroy methods.
  • Either you use the method onRetainNonConfigurationInstance, but that is not enough, to avoid memory leaks, you also have to extend the class Runnable to inject two Booleans able to stop it.

short, download the tutorials below if you want to be respectful when you use Threads.
Ah, yes, for more information, I posted some notes on my blog about this issue : http://android2ee.blogspot.com/  (those of the 15/12/2011 and the 21/11/2011). There is also an article (in french sorry about that) on developpez.com:Article on Handlers, AsyncTasks, Threads and memory leaks
I wish you a good download and a good understanding of the use of handlers.

Tutorials download


These tutorials show how to use handlers.

Each tutorial is a zipped Eclipse project, directly importable into your workspace.

Download in a single file all these tutorials:

 Download them all

 

 
Memory leaks
demonstartion
Handler Tutorial
with AtomicBoolean
Handler Tutorial with
onRetainNonConfiguration
HandlerMemoryLeakDemo HandlerTuto HandlerActivityBindingThreadTuto

 Download

 Download

 Download

AsyncTask Tutorial
with AtomicBoolean
Memory Leaks
Demonstration
with AsyncTask
AsyncTaskTuto OrphanAsyncTaskThreadTuto

 Download

 Download


This code is free for any usage but can't be distributed.

Its distirbution and its intelectual property belongs to the web site:

http://android2ee.com.

The use of those codes is under your own responsability and nobody (else than you) can be considered as responsible for any loss or damage of any nature that results from this usage.

All the quoted products name or marks of this books are trade marks by their respective owners.

You are here Examples Tutorials Handler's Tutorials