Cette présentation a été donnée à l'Eclipse Day Toulouse 2012 par Android2EE - Mathias Seguy (1/2h).
L’objectif est de présenter l'utilisation du plugin Android pour eclipse, en particulier la Vue DDMS. Cette présentation se finit par la mise en place de la chasse d'une fuite mémoire dans un programme Android avec l'utilisation du Heap dump et du plugin MAT d'eclipse (Memory analysis Tool).
Cette présentation est une présentation d’Android2EE, entreprise spécialisée dans l’expertise, le consulting et la formation Android. Vous souhaitez apprendre la programmation Android, Android2EE vous accompagne au-travers ses EBooks ou ses formations.
Laissez moi vous raconter mon histoire concernant cette entreprise. En 2010, je me suis penché sur la technologie Android, j’ai écrit trois EBooks sur l’art de la programmation Android (disponible sur Android2EE). J’ai quitté ma précédente entreprise et j’ai créé l’entreprise Android2EE (Android To Enterprise Edition) dont l’objectif est la formation, l’expertise et le consulting Android. J’ai quelques contrats en tant que consultant et aussi en tant que formateur. J’ai monté un ensemble de formations Android pour les entreprises:
Formation Initiale : Devenir autonome (3j).
Formation Approfondissement (2j).
Formation Spécificité Tablette et Graphisme(2j).
Formation Applications complexes (2j).
Formation chef de projet - responsable technique (1j).
Formation Mutlimédia (2j).
Formation sur mesure (2 à 3j).
Je pratique ces formations en donnant des cours dans les universités et les écoles d’ingénieurs de Toulouse ainsi que dans de grandes conférences Java:
CESI-EXIA, EPITECH, Sup-Info, IUP ISI, InfoSup, IUP SI, IUP ISI, IngeSup, INSA
Et bien sûr: Devoxx France (LA conférence Java française de 2012), Mercredi 18 Avril 2012,
Et
JCertif Afrique 2012 (LA conférence Java du continent Africain) Septembre 2012 Conférence et Cours
Enfin, j’ai investi l’espace numérique, voici quelques uns des ces sites:
http://www.android2ee.com/
http://mathias-seguy.developpez.com/
http://blog.developpez.com/android2ee-mathias-seguy/
http://android2ee.blogspot.com/
La critique de mon livre « Android A Complete course » par developpez.com (dont je ne suis pas peu fier, quand même):
http://android.developpez.com/livres/#L9791090388000
J’ai des articles sur Developpez.com concernant Android.
Ah oui, j’oubliais, mon cv se trouve ici (si jamais) : http://mathias-seguy.developpez.com/MathiasSeguyCV201106/
2. •Android in numbers
•Installing the work space
•Creating a project
•Using DDMS perspective
•Using DDMS perspective and Eclipse Debug Bridge
•Tracking memory leaks
2
3. Android Trainer Consultant Expert
mathias.seguy.it@gmail.com (mail)
@android2ee (twitter)
Author of eBooks on Android programming (Android2ee.com)
Android Speaker and Teacher
Fundamentals Mathematics Doctor
Technical expert of the “Agence Nationale de la Recherche”
Developpez.com Redactor
Android Blogs : Android2EE sur DVP et Android2ee sur BlogSpot
Fundamentals
Mathematics Android2EE
PHD Via CapGemini Via Sopra Birth
Siemens Magnus DGA CNES Airbus Airbus Airbus STI Android2
VDO EE
03 04 05 06 07 08 09 10 11 12
Java J2EE
Android
Manager Manager Technical
Developer Developer GUI Leader Technical Technical Manager Technical Director Android2EE
Leader Leader Leader Founder
ENSEEIHT‟s IT At STI
Master
3
5. •2003 Android Inc creation
•2005 Google bought Android
•2007 Open Handset Alliance birth
•2007 Android Beta SDK released
In 3 years, from September 2008 to
November 2011, 8 major versions of the
system are delivered by Google
5
6. Android in numbers:
• 27% of mobiles are smart phones (World Wild, 2011);
• 52.5% of smart phones are Android phones (World Wild, Dec 2011);
• 1 smart phone over two sold is an Android Phone (US, Dec 2011);
• +17391% of available applications on GooglePlay in 3 years;
• +500 000 applications in GooglePlay (April 2012);
• +15 000 000 downloads (May 2012);
• 2012 will be the Android Tablet year.
Ok, today, Android is the smart phones OS winner.
But tomorrow, Android will be everywhere: mobile, tablet, TV, watches, Hifi, car, appliances, home automation
Everywhere, I tell you.
6
8. It‟s pretty easy:
First:
• Download Java
(http://www.oracle.com/technetwork/java/javase/do
wnloads/index.html) and install it;
• Download Eclipse
(http://www.eclipse.org/downloads/) and install it;
• Download the Android SDK
(http://developer.android.com/sdk/index.html) and
unzip it.
In Eclipse, add the Android plugin:
• Go in Help/install New software. Click Add and
set Android and https://dl-
ssl.google.com/android/eclipse/
• Select all the elements, click next and finish.
Restart Eclipse :
• In WindowPreference select Android et set the
Android SDK path (the folder in which you unzip
the Android SDK)
Ok, it‟s done, you can code Android program.
9. Now open the SDK Manager
And launch the update/installation (Android SDK Tools,
platform-tools, SDK, documentation,…).
A long download is waiting for you.
Then define Android Virtual Device (Emulator) for tests.
10. Now open the SDK Manager
A quick glance at the window.
14. Let‟s create a first project a see :
• Android “new project” Wizard
• Android Manifest wysiwyg
• Android Layout wysiwyg
• Android resources wysiwyg
14
15. Let‟s create a first project a see :
File->new->Others…-> Android Project and follow the wizard:
Project Name, Project SDK to target,
15
16. Let‟s create a first project a see :
File->new->Others…-> Android Project and follow the wizard:
Project Name, Project SDK to target, Application name, Package name, Activity name, min SDK,
Project created
16
21. Open the DDMS perspective.
• Devices
• Emulator Control
• Set of action buttons
• File Explorer
• Resource explorer
• Lint Warning
• LogCat
21
22. Status Version/Tid/Pid
Devices Connected
Avaiable Processes
to watch
22
23. Control the emulator telephony status
Emulate a phone call to the emulator
Emulate the reception of an SMS
Control the emulator geo-location using:
Your own lat/long
A GPX file
A KML file
23
24. Screen
Debug Heap Thread Stop Capture
Take a
screen
shoot
Strart the « Debug » Stop a process
on a Process
Begin CPU time
Begin the Heap Cause Garbage tracking
tracking using the Collector usefull to
Heap View update heap stats Begin threads
tracking using the
Dump the Heap Threads View
within Eclipse (using
MAT) or in a file
24
25. Create a folder
Delete a file
Push a file onto the
device
Pull a file from the
device
25
36. It‟s quiet simple: Thread I.H.M Thread de traitement
Link an activity with a life cycle and a Activity Handler
thread with no management sendMessage(
between the thread lifecycle and the )
message
OnDestroy()
OnCreate()
Thread de traitement initiale
Thread I.H.M sendMessage
()
Activity Handler
fantôme fantôme
Thread de traitement
Activity Handler
sendMessage(
)
message
36
39. Application
Main
Activity 1 Handler 1 Thread 1
Main
Activity 2 Handler 2 Thread 2
Main
Activity 3 Handler 3 Thread 3
39
40. Shallow heap is the memory consumed by one object. GC Root
S=100
Retained set of X is the set of objects which would be R=400
removed by GC when X is garbage collected.
Retained heap of X is the sum of shallow sizes of all objects
in the retained set of X, i.e. memory kept alive by X.
Generally speaking, shallow heap of an object is its size in the
heap and retained size of the same object is the amount of S=100 S=100
heap memory that will be freed when the object is garbage R=200 R=100
collected.
S=100
R=100
40
41. Using the Debug mode with
the DDMS perspective.
• Allocation tracker
• Heap tracking
• Threads tracking
• Heap Dump
• Save the heap,
• Convert the heap using: hpro-conv dump.hprof dump-converted.hprof
• D:Eclipseeclipsex64_indigo_Androidandroid-sdktools>hprof-conv.exe
D:AndroidConferenceEclipseDayToulousehrpofcom.android2ee.tuto.thread.orphan.hprof
D:AndroidConferenceEclipseDayToulousehrpofcom.android2ee.tuto.thread.orphan.converted.prof
41
42. • Open it in MAT the converted hprof
• Dominator tree => We detect our Thread
42
43. • Open it in MAT the converted hprof
• Dominator tree => We detect our Thread
43
44. • Now, open the Histogram View
• Choose byte[] and select “list object with incoming reference”
44
45. • Now, open the Histogram View
• Choose byte[] and select “list object with incoming reference”
• Open the items and fall on your class and select “list object with incoming reference”
45
46. • Now, open the Histogram View
• Choose byte[] and select “list object with incoming reference”
• Open the items and fall on your class and select “list object with incoming reference”
• Find again the duplicated activity
46
47. • Now, open the Histogram View
• Choose byte[] and select “list object with incoming reference”
• Open the items and fall on your class and select “list object with incoming reference”
• Find again the duplicated activity
Open one of then and Just look at the Handler and the Background Thread => Leak Resolved
47
48. This presentation has used the following references:
• Android2ee„s Ebooks and tutorials : http://www.android2ee.com
• Android web sites:
• http://developer.android.com/index.html
• http://android-developers.blogspot.fr/
• http://www.google.com/events/io/2011/sessions.html
• Android Design Guide: http://developer.android.com/design/index.html
On Android2ee, you‟ll find the following tutorials:
• Sensors
• Threads, handlers and memory leaks
• AppWidgets
• Dynamic GUI creation
• REST Services
• RSS reader
• Use Maven for Android projects
• Deliver on GooglePlay
Sur developpez.com vous trouverez les articles suivants (français seulement):
•Déployer son application Android et obtenir sa clef MapView.
•Construire dynamiquement ses IHM Android
•Les capteurs Android
•Thread, Handler, AsyncTask et fuites mémoires
•Investir l'écran d'accueil Android avec les AppWidgets
•Android, Livrer son projet sur GooglePlay
48
49. .
Thanks for your attention.
android2ee.com. See you in:
Brazzaville
#android2ee In September
mathias.seguy.it@gmail.com
MySensors, MyLight et MyTorch
available on GooglePlay
49