SlideShare a Scribd company logo
Android Dev Tips
Kanda Runapongsa Saikaew
Agenda
1. 
2. 
3. 
4. 
5. 

Love Relative Layout
Use Hierarchy Viewer
Use Eclipse Effectively
Use LogCat
Publish Application
1. Love Relative Layout
•  Most of the tutorials use LinearLayout, but you will find
• 
• 

that RelativeLayout is truly useful
A common example is the abuse of LinearLayout, which
leads to a proliferation of views in the view hierarchy
Every view, or worse every layout manager, you add to
your application comes at a cost: initialization, layout
and drawing become slower
Use LinearLayout
Use RelativeLayout
2. Use Hierarchy Viewer
•  The Android SDK tools include a tool called Hierarchy
Viewer that allows you to analyze your layout while your
application is running
•  Hierarchy Viewer works by allowing you to select running
processes on a connected device or emulator, then display
the layout tree
•  The traffic lights on each block represent its Measure,
Layout and Draw performance, helping you identify potential
issues.
Using HierarchyViewer
• 
• 

The hierarchyviewer tool is available in <sdk>/tools/
When opened, the Hierarchy Viewer shows a list of
available devices and its running components
Using Hierarchy Viewer
•  Click Load View Hierarchy to view the
layout hierarchy of the selected component
Using Hierarchy Viewer
-  A small bitmap image on the left
-  Two stacked items of text on the right
Using LinearLayout
Using LinearLayout
•  There is a 3-level hierarchy with some
problems laying out the text items
•  The timings for rendering a complete list
item using this layout are
• 
• 
• 

Measure: 0.977ms
Layout: 0.167ms
Draw: 2.717ms
Using RelativeLayout
Using RelativeLayout
• 

Because the layout performance above slows down due to
a nested LinearLayout
•  The performance might improve by flattening the layout—
make the layout shallow and wide, rather than narrow and
deep
•  Now rendering a list item takes
•  Measure: 0.598ms
•  Layout: 0.110ms
•  Draw: 2.146ms
3. Use Eclipse Effectively

• 
• 
• 

You should try to keep your hands on
keyboard
The less you touch the mouse, the more
code you can write
I am trying to keep the mouse laying still and
control the IDE completely using keyboard.
Eclipse Short Cut Keys
• 
• 
• 
• 
• 

Ctrl + D
Ctrl + 1
Ctrl + Shift + O
Ctrl + Shift + F
Ctrl + Shift + L

Delete row
Activates the quick fix
Organize imports
Format codes
Shows you a list of your
currently defined
shortcut keys
4. Use LogCat
•  It can be difficult in Android to figure out

• 

“what went wrong”.
LogCat will show cause of the problems.
o 
o 

Error message with red string.
Problems that cause by …. (something) with line of
that code.
How to Use LogCat
•  To use LogCat, first import android.util.Log
into your project
•  Now you can call the static class Log from
your project to start logging
•  Logcat has different levels of logging
Different Levels of Logging
V — Verbose (lowest priority)
D — Debug
I — Info
W — Warning
E — Error
F — Fatal
S — Silent (highest priority, on which nothing is ever
printed)
Setting Different Colors for Different Levels

•  Go to Preferences > LogCat > Colors
Example of Using Log Class
How to View LogCat
• 
• 
• 

Open LogCat view by clicking the LogCat icon at the
bottom right corner (1 in the figure)
Filter LogCat level (2 in the figure)
Search for some keyword (3 in the figure)
5. Publish Application
•  Prepare the application for release
•  Release the application to users
Configure Your Application for Release

•  Choose a good package
• 

The package name cannot start with com.example

•  Turn off logging and debugging
• 
• 
• 

Remove Log calls
Remove android:debuggable attribute from your
manifest file
Remove all Debug tracing calls such as
startMethodTracing()
Configure Your Application for Release
•  Clean up your directory
• 

Review the contents of your jni/, lib/, and src/ directories
•  The jni/ directory should contain only source files
associated with the Android NDK, such as .c, .cpp, .h,
and .mk files
•  The lib/ directory should contain only third-party library
files or private library files, including prebuilt shared and
static libraries
•  The src/ directory should not contain any .jar files.
Configure Your Application for Release
•  Review and update your manifest settings
•  <uses-permission> element
•  You should specify only those permissions that are
relevant and required for application
•  android:icon and android:label attributes
•  You must specify values for these attributes, which are
located in the <application> element
•  android:versionCode and android:versionName attributes.
•  We recommend that you specify values for these
attributes
Configure Your Application for Release
• 

Address compatibility issues
• 
• 

Add support for multiple screen configurations.
Optimize your application for Android tablet devices.
•  If your application is designed for devices older than
Android 3.0, make it compatible with Android 3.0 devices

• 

Consider using the Support Library.
• 
If your application is designed for devices running Android 3.x,
make your application compatible with older versions of Android
Support Different Devices
•  Support different languages
•  Support different screens
•  Different layouts
•  Different bitmaps
•  Different text sizes
Support Different Languages
• 
• 

Create the resource subdirectories and string resource
files
Example

MyProject/
res/
values/
strings.xml
values-es/
strings.xml
Support Different Languages
English (default locale), /values/strings.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="title">My Application</string>
<string name="hello_world">Hello World!</string>
</resources>
Spanish, /values-es/strings.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="title">Mi Aplicación</string>
<string name="hello_world">Hola Mundo!</string>
</resources>
Support Different Screens
•  Android categorizes device screens using two
general properties: size and density
•  There are four generalized sizes: small,
normal, large, xlarge
•  Four generalized densities: low (ldpi), medium
(mdpi), high (hdpi), extra high (xhdpi)
Support Different Layouts
MyProject/
res/
layout/
main.xml

# default (portrait)

layout-land/

# landscape

main.xml
layout-large/

# large (portrait)

main.xml
layout-large-land/ # large landscape
main.xml
Support Different Bitmaps
•  To generate these images, you should start with your raw resource
in vector format and generate the images for each density using
the following size scale:
• 
• 

xhdpi: 2.0
hdpi: 1.5

• 
• 

mdpi: 1.0 (baseline)
ldpi: 0.75

•  This means that if you generate a 200x200 image for xhdpi
devices, you should generate the same resource in 150x150 for
hdpi, 100x100 for mdpi, and 75x75 for ldpi devices.
Support Different Bitmaps
Then, place the files in the appropriate drawable resource directory:
MyProject/
res/
drawable-xhdpi/
awesomeimage.png
drawable-hdpi/
awesomeimage.png
drawable-mdpi/
awesomeimage.png
Any time you reference @drawable/awesomeimage, the system selects the
appropriate bitmap based on the screen's density.
Support Different Text Sizes
• 

You should use the resource folders such as

values-ldpi
values-mdpi
values-hdpi
• 

Write the text size in 'dimensions.xml' file for each range

Sample dimensions.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="textsize">15sp</dimen>
</resources>
• 

In Java code, textView.setTextSize(getResources().getDimension(R.dimen.textsize));
What to Test
•  Change in orientation
• 
• 

Is the screen re-drawn correctly?
Does the application maintain its state?

•  Change in configuration
• 

A situation that is more general than a change in
orientation is a change in the device's configuration,
such as a change in the availability of a keyboard or
a change in system language
What to Test
•  Battery Life
• 

• 

You need to write your application to minimize
battery usage, you need to test its battery
performance, and you need to test the methods that
manage battery usage.
Techniques for minimizing battery usage were
presented at the 2010 Google I/O conference in the
presentation Coding for Life -- Battery Life, That Is.
What to Test
•  Dependence on external resources
•  If your application depends on network access,
SMS, Bluetooth, or GPS, then you should test what
happens when the resource or resources are not
available
•  For example, if your application uses the network, it
can notify the user if access is unavailable, or
disable network-related features, or do both
References
• 
• 
• 
• 
• 
• 
• 
• 
• 

http://stackoverflow.com/questions/2961049/effective-android-programmingtechniques
http://www.curious-creature.org/2009/02/22/android-layout-tricks-1/
http://www.curious-creature.org/2012/12/01/android-performance-case-study/
http://developer.android.com/training/improving-layouts/optimizing-layout.html
http://eclipse.dzone.com/news/effective-eclipse-shortcut-key
http://developer.android.com/tools/testing/what_to_test.html
http://developer.android.com/tools/publishing/preparing.html
http://stackoverflow.com/questions/9494037/how-to-set-text-size-of-textviewdynamically-for-diffrent-screens
http://developer.android.com/training/basics/supporting-devices/screens.html
Thank you
Kanda Runapongsa Saikaew
•  Khon Kaen University, Thailand
• 
• 

• 
• 
• 

Assistant Professor of Department of Computer Engineering
Associate Director for Administration of Computer Center

krunapon@kku.ac.th
Twitter: @krunapon
G+: https://plus.google.com/u/0/118244887738724224199

More Related Content

What's hot (20)

PPTX
Building a TV show with Angular, Bootstrap, and Web Services
David Giard
 
PPT
Google App Engine for Java
Lars Vogel
 
PDF
Introduction to Google App Engine - Naga Rohit S [ IIT Guwahati ] - Google De...
Naga Rohit
 
PDF
Google cloud endpoints
Dimitar Danailov
 
PDF
Angular 4 for Java Developers
Yakov Fain
 
PPT
Developing Java Web Applications In Google App Engine
Tahir Akram
 
PDF
Urban Airship & Android Application Integration Document
mobi fly
 
PDF
Urban Airship and Android Integration for Push Notification and In-App Notifi...
Zeeshan Rahman
 
PPTX
Ajax
Gayathri Ganesh
 
PDF
Salesforce Lightning Tips & Tricks
Thinqloud
 
PPTX
MongoDB.local Seattle 2019: MongoDB Stitch Tutorial
MongoDB
 
PDF
[React-Native Tutorial 10] Camera Roll / Gallery / Camera / Native Modules by...
Kobkrit Viriyayudhakorn
 
PPTX
Introduction to angular with a simple but complete project
Jadson Santos
 
PDF
AppSyncをReactで使ってみた
Takahiro Kobaru
 
PDF
Alon Fliess: APM – What Is It, and Why Do I Need It? - Architecture Next 20
CodeValue
 
PPT
Google App Engine
Sanguine_Eva
 
PDF
Introduction to React Native
Rami Sayar
 
PDF
Meteor.js for DOers
ShavonnahTiera
 
PPTX
Developing Android Client Apps via SyncAdapter
Anatoliy Kaverin
 
PPTX
Phonegap android angualr material design
Srinadh Kanugala
 
Building a TV show with Angular, Bootstrap, and Web Services
David Giard
 
Google App Engine for Java
Lars Vogel
 
Introduction to Google App Engine - Naga Rohit S [ IIT Guwahati ] - Google De...
Naga Rohit
 
Google cloud endpoints
Dimitar Danailov
 
Angular 4 for Java Developers
Yakov Fain
 
Developing Java Web Applications In Google App Engine
Tahir Akram
 
Urban Airship & Android Application Integration Document
mobi fly
 
Urban Airship and Android Integration for Push Notification and In-App Notifi...
Zeeshan Rahman
 
Salesforce Lightning Tips & Tricks
Thinqloud
 
MongoDB.local Seattle 2019: MongoDB Stitch Tutorial
MongoDB
 
[React-Native Tutorial 10] Camera Roll / Gallery / Camera / Native Modules by...
Kobkrit Viriyayudhakorn
 
Introduction to angular with a simple but complete project
Jadson Santos
 
AppSyncをReactで使ってみた
Takahiro Kobaru
 
Alon Fliess: APM – What Is It, and Why Do I Need It? - Architecture Next 20
CodeValue
 
Google App Engine
Sanguine_Eva
 
Introduction to React Native
Rami Sayar
 
Meteor.js for DOers
ShavonnahTiera
 
Developing Android Client Apps via SyncAdapter
Anatoliy Kaverin
 
Phonegap android angualr material design
Srinadh Kanugala
 

Viewers also liked (11)

PPTX
Mobile Dev Talk #0 Keynote & Mobile Trend 2015
Sittiphol Phanvilai
 
PPTX
Android dev toolbox
Shem Magnezi
 
PDF
Andriod dev toolbox part 2
Shem Magnezi
 
PDF
Android ui tips & tricks
Shem Magnezi
 
PDF
Know what (not) to build
Shem Magnezi
 
PPTX
Summit 2015: Mobile App Dev and Content Management with Adobe Experience Manager
brucelefebvre
 
PDF
Tracxn Research — Mobile Dev Tools Landscape, November 2016
Tracxn
 
PDF
Android Dev Tools Knowledge
Shinobu Okano
 
PDF
2nd Athens Android Dev Meetup: Hello Android, from zero to hello
Mando Stam
 
PPT
PPT Companion to Android
Dharani Kumar Madduri
 
PPT
Android ppt
blogger at indiandswad
 
Mobile Dev Talk #0 Keynote & Mobile Trend 2015
Sittiphol Phanvilai
 
Android dev toolbox
Shem Magnezi
 
Andriod dev toolbox part 2
Shem Magnezi
 
Android ui tips & tricks
Shem Magnezi
 
Know what (not) to build
Shem Magnezi
 
Summit 2015: Mobile App Dev and Content Management with Adobe Experience Manager
brucelefebvre
 
Tracxn Research — Mobile Dev Tools Landscape, November 2016
Tracxn
 
Android Dev Tools Knowledge
Shinobu Okano
 
2nd Athens Android Dev Meetup: Hello Android, from zero to hello
Mando Stam
 
PPT Companion to Android
Dharani Kumar Madduri
 
Ad

Similar to Android dev tips (20)

PPTX
Consistent UI Across Android Devices
Irene Duke
 
PPTX
Android Studio development model and.pptx
VaibhavKhunger2
 
PPTX
Android webinar class_1
Edureka!
 
PDF
Android
Edureka!
 
PPT
Introduction to android sessions new
Joe Jacob
 
PPTX
Android app development
Abhishek Saini
 
PDF
Android app development by abhi android
susijanny
 
PPTX
Introduction to android basics
Hasam Panezai
 
PPT
Android project architecture
Sourabh Sahu
 
PDF
Beating Android Fragmentation, Brett Duncavage
Xamarin
 
PPTX
Session 2 beccse
vin123456gangal
 
PDF
Learn Android at edureka!
Edureka!
 
PPTX
Intro to android (gdays)
Omolara Adejuwon
 
PPTX
Developing for Android-Types of Android Application
Nandini Prabhu
 
PPTX
Mobile Application Slide Chapter 2 - Make First App
sesam37434
 
PPT
Android - Android Application Configuration
Vibrant Technologies & Computers
 
PPTX
Browser Developer Tools for APEX Developers
Christian Rokitta
 
PDF
Matteo Gazzurelli - Andorid introduction - Google Dev Fest 2013
DuckMa
 
PPT
Lecture 1 Android Application Development.ppt
hillarykiprono4
 
PDF
Chapter 9 - Resources System
Sittiphol Phanvilai
 
Consistent UI Across Android Devices
Irene Duke
 
Android Studio development model and.pptx
VaibhavKhunger2
 
Android webinar class_1
Edureka!
 
Android
Edureka!
 
Introduction to android sessions new
Joe Jacob
 
Android app development
Abhishek Saini
 
Android app development by abhi android
susijanny
 
Introduction to android basics
Hasam Panezai
 
Android project architecture
Sourabh Sahu
 
Beating Android Fragmentation, Brett Duncavage
Xamarin
 
Session 2 beccse
vin123456gangal
 
Learn Android at edureka!
Edureka!
 
Intro to android (gdays)
Omolara Adejuwon
 
Developing for Android-Types of Android Application
Nandini Prabhu
 
Mobile Application Slide Chapter 2 - Make First App
sesam37434
 
Android - Android Application Configuration
Vibrant Technologies & Computers
 
Browser Developer Tools for APEX Developers
Christian Rokitta
 
Matteo Gazzurelli - Andorid introduction - Google Dev Fest 2013
DuckMa
 
Lecture 1 Android Application Development.ppt
hillarykiprono4
 
Chapter 9 - Resources System
Sittiphol Phanvilai
 
Ad

More from Kanda Runapongsa Saikaew (20)

PDF
ความรู้ไอทีช่วยเลี้ยงลูกได้
Kanda Runapongsa Saikaew
 
PDF
Google Apps Basic for Education
Kanda Runapongsa Saikaew
 
PDF
Moodle basics
Kanda Runapongsa Saikaew
 
PDF
Thai socialmedia
Kanda Runapongsa Saikaew
 
PDF
Introduction to JSON
Kanda Runapongsa Saikaew
 
PDF
Introduction to Google+
Kanda Runapongsa Saikaew
 
PDF
ใช้ไอทีอย่างไรให้เป็นประโยชน์ เหมาะสม และปลอดภัย
Kanda Runapongsa Saikaew
 
PDF
บริการไอทีของมหาวิทยาลัยขอนแก่นเพื่อนักศึกษา
Kanda Runapongsa Saikaew
 
PPT
Baby Health Journal
Kanda Runapongsa Saikaew
 
PDF
Using Facebook as a Supplementary Tool for Teaching and Learning
Kanda Runapongsa Saikaew
 
PDF
วิธีการติดตั้งและใช้ Dropbox
Kanda Runapongsa Saikaew
 
PDF
Using Facebook and Google Docs for Teaching and Sharing Information
Kanda Runapongsa Saikaew
 
PDF
เครื่องมือเทคโนโลยีสารสนเทศฟรีที่น่าใช้
Kanda Runapongsa Saikaew
 
PDF
การใช้เฟซบุ๊กเพื่อแลกเปลี่ยนเรียนรู้
Kanda Runapongsa Saikaew
 
PDF
คู่มือการใช้ Dropbox
Kanda Runapongsa Saikaew
 
PDF
การใช้เฟซบุ๊กเพื่อการเรียนการสอน
Kanda Runapongsa Saikaew
 
PDF
การใช้เฟซบุ๊กอย่างปลอดภัยและสร้างสรรค์
Kanda Runapongsa Saikaew
 
PDF
Social Media (โซเชียลมีเดีย)
Kanda Runapongsa Saikaew
 
PDF
Mobile Application for Education (โมบายแอปพลิเคชันเพื่อการศึกษา)
Kanda Runapongsa Saikaew
 
PDF
Google bigtableappengine
Kanda Runapongsa Saikaew
 
ความรู้ไอทีช่วยเลี้ยงลูกได้
Kanda Runapongsa Saikaew
 
Google Apps Basic for Education
Kanda Runapongsa Saikaew
 
Thai socialmedia
Kanda Runapongsa Saikaew
 
Introduction to JSON
Kanda Runapongsa Saikaew
 
Introduction to Google+
Kanda Runapongsa Saikaew
 
ใช้ไอทีอย่างไรให้เป็นประโยชน์ เหมาะสม และปลอดภัย
Kanda Runapongsa Saikaew
 
บริการไอทีของมหาวิทยาลัยขอนแก่นเพื่อนักศึกษา
Kanda Runapongsa Saikaew
 
Baby Health Journal
Kanda Runapongsa Saikaew
 
Using Facebook as a Supplementary Tool for Teaching and Learning
Kanda Runapongsa Saikaew
 
วิธีการติดตั้งและใช้ Dropbox
Kanda Runapongsa Saikaew
 
Using Facebook and Google Docs for Teaching and Sharing Information
Kanda Runapongsa Saikaew
 
เครื่องมือเทคโนโลยีสารสนเทศฟรีที่น่าใช้
Kanda Runapongsa Saikaew
 
การใช้เฟซบุ๊กเพื่อแลกเปลี่ยนเรียนรู้
Kanda Runapongsa Saikaew
 
คู่มือการใช้ Dropbox
Kanda Runapongsa Saikaew
 
การใช้เฟซบุ๊กเพื่อการเรียนการสอน
Kanda Runapongsa Saikaew
 
การใช้เฟซบุ๊กอย่างปลอดภัยและสร้างสรรค์
Kanda Runapongsa Saikaew
 
Social Media (โซเชียลมีเดีย)
Kanda Runapongsa Saikaew
 
Mobile Application for Education (โมบายแอปพลิเคชันเพื่อการศึกษา)
Kanda Runapongsa Saikaew
 
Google bigtableappengine
Kanda Runapongsa Saikaew
 

Recently uploaded (20)

PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
Biography of Daniel Podor.pdf
Daniel Podor
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PDF
Blockchain Transactions Explained For Everyone
CIFDAQ
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PDF
IoT-Powered Industrial Transformation – Smart Manufacturing to Connected Heal...
Rejig Digital
 
PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
PDF
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Biography of Daniel Podor.pdf
Daniel Podor
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
Blockchain Transactions Explained For Everyone
CIFDAQ
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
IoT-Powered Industrial Transformation – Smart Manufacturing to Connected Heal...
Rejig Digital
 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 

Android dev tips

  • 1. Android Dev Tips Kanda Runapongsa Saikaew
  • 2. Agenda 1.  2.  3.  4.  5.  Love Relative Layout Use Hierarchy Viewer Use Eclipse Effectively Use LogCat Publish Application
  • 3. 1. Love Relative Layout •  Most of the tutorials use LinearLayout, but you will find •  •  that RelativeLayout is truly useful A common example is the abuse of LinearLayout, which leads to a proliferation of views in the view hierarchy Every view, or worse every layout manager, you add to your application comes at a cost: initialization, layout and drawing become slower
  • 6. 2. Use Hierarchy Viewer •  The Android SDK tools include a tool called Hierarchy Viewer that allows you to analyze your layout while your application is running •  Hierarchy Viewer works by allowing you to select running processes on a connected device or emulator, then display the layout tree •  The traffic lights on each block represent its Measure, Layout and Draw performance, helping you identify potential issues.
  • 7. Using HierarchyViewer •  •  The hierarchyviewer tool is available in <sdk>/tools/ When opened, the Hierarchy Viewer shows a list of available devices and its running components
  • 8. Using Hierarchy Viewer •  Click Load View Hierarchy to view the layout hierarchy of the selected component
  • 9. Using Hierarchy Viewer -  A small bitmap image on the left -  Two stacked items of text on the right
  • 11. Using LinearLayout •  There is a 3-level hierarchy with some problems laying out the text items •  The timings for rendering a complete list item using this layout are •  •  •  Measure: 0.977ms Layout: 0.167ms Draw: 2.717ms
  • 13. Using RelativeLayout •  Because the layout performance above slows down due to a nested LinearLayout •  The performance might improve by flattening the layout— make the layout shallow and wide, rather than narrow and deep •  Now rendering a list item takes •  Measure: 0.598ms •  Layout: 0.110ms •  Draw: 2.146ms
  • 14. 3. Use Eclipse Effectively •  •  •  You should try to keep your hands on keyboard The less you touch the mouse, the more code you can write I am trying to keep the mouse laying still and control the IDE completely using keyboard.
  • 15. Eclipse Short Cut Keys •  •  •  •  •  Ctrl + D Ctrl + 1 Ctrl + Shift + O Ctrl + Shift + F Ctrl + Shift + L Delete row Activates the quick fix Organize imports Format codes Shows you a list of your currently defined shortcut keys
  • 16. 4. Use LogCat •  It can be difficult in Android to figure out •  “what went wrong”. LogCat will show cause of the problems. o  o  Error message with red string. Problems that cause by …. (something) with line of that code.
  • 17. How to Use LogCat •  To use LogCat, first import android.util.Log into your project •  Now you can call the static class Log from your project to start logging •  Logcat has different levels of logging
  • 18. Different Levels of Logging V — Verbose (lowest priority) D — Debug I — Info W — Warning E — Error F — Fatal S — Silent (highest priority, on which nothing is ever printed)
  • 19. Setting Different Colors for Different Levels •  Go to Preferences > LogCat > Colors
  • 20. Example of Using Log Class
  • 21. How to View LogCat •  •  •  Open LogCat view by clicking the LogCat icon at the bottom right corner (1 in the figure) Filter LogCat level (2 in the figure) Search for some keyword (3 in the figure)
  • 22. 5. Publish Application •  Prepare the application for release •  Release the application to users
  • 23. Configure Your Application for Release •  Choose a good package •  The package name cannot start with com.example •  Turn off logging and debugging •  •  •  Remove Log calls Remove android:debuggable attribute from your manifest file Remove all Debug tracing calls such as startMethodTracing()
  • 24. Configure Your Application for Release •  Clean up your directory •  Review the contents of your jni/, lib/, and src/ directories •  The jni/ directory should contain only source files associated with the Android NDK, such as .c, .cpp, .h, and .mk files •  The lib/ directory should contain only third-party library files or private library files, including prebuilt shared and static libraries •  The src/ directory should not contain any .jar files.
  • 25. Configure Your Application for Release •  Review and update your manifest settings •  <uses-permission> element •  You should specify only those permissions that are relevant and required for application •  android:icon and android:label attributes •  You must specify values for these attributes, which are located in the <application> element •  android:versionCode and android:versionName attributes. •  We recommend that you specify values for these attributes
  • 26. Configure Your Application for Release •  Address compatibility issues •  •  Add support for multiple screen configurations. Optimize your application for Android tablet devices. •  If your application is designed for devices older than Android 3.0, make it compatible with Android 3.0 devices •  Consider using the Support Library. •  If your application is designed for devices running Android 3.x, make your application compatible with older versions of Android
  • 27. Support Different Devices •  Support different languages •  Support different screens •  Different layouts •  Different bitmaps •  Different text sizes
  • 28. Support Different Languages •  •  Create the resource subdirectories and string resource files Example MyProject/ res/ values/ strings.xml values-es/ strings.xml
  • 29. Support Different Languages English (default locale), /values/strings.xml: <?xml version="1.0" encoding="utf-8"?> <resources> <string name="title">My Application</string> <string name="hello_world">Hello World!</string> </resources> Spanish, /values-es/strings.xml: <?xml version="1.0" encoding="utf-8"?> <resources> <string name="title">Mi Aplicación</string> <string name="hello_world">Hola Mundo!</string> </resources>
  • 30. Support Different Screens •  Android categorizes device screens using two general properties: size and density •  There are four generalized sizes: small, normal, large, xlarge •  Four generalized densities: low (ldpi), medium (mdpi), high (hdpi), extra high (xhdpi)
  • 31. Support Different Layouts MyProject/ res/ layout/ main.xml # default (portrait) layout-land/ # landscape main.xml layout-large/ # large (portrait) main.xml layout-large-land/ # large landscape main.xml
  • 32. Support Different Bitmaps •  To generate these images, you should start with your raw resource in vector format and generate the images for each density using the following size scale: •  •  xhdpi: 2.0 hdpi: 1.5 •  •  mdpi: 1.0 (baseline) ldpi: 0.75 •  This means that if you generate a 200x200 image for xhdpi devices, you should generate the same resource in 150x150 for hdpi, 100x100 for mdpi, and 75x75 for ldpi devices.
  • 33. Support Different Bitmaps Then, place the files in the appropriate drawable resource directory: MyProject/ res/ drawable-xhdpi/ awesomeimage.png drawable-hdpi/ awesomeimage.png drawable-mdpi/ awesomeimage.png Any time you reference @drawable/awesomeimage, the system selects the appropriate bitmap based on the screen's density.
  • 34. Support Different Text Sizes •  You should use the resource folders such as values-ldpi values-mdpi values-hdpi •  Write the text size in 'dimensions.xml' file for each range Sample dimensions.xml <?xml version="1.0" encoding="utf-8"?> <resources> <dimen name="textsize">15sp</dimen> </resources> •  In Java code, textView.setTextSize(getResources().getDimension(R.dimen.textsize));
  • 35. What to Test •  Change in orientation •  •  Is the screen re-drawn correctly? Does the application maintain its state? •  Change in configuration •  A situation that is more general than a change in orientation is a change in the device's configuration, such as a change in the availability of a keyboard or a change in system language
  • 36. What to Test •  Battery Life •  •  You need to write your application to minimize battery usage, you need to test its battery performance, and you need to test the methods that manage battery usage. Techniques for minimizing battery usage were presented at the 2010 Google I/O conference in the presentation Coding for Life -- Battery Life, That Is.
  • 37. What to Test •  Dependence on external resources •  If your application depends on network access, SMS, Bluetooth, or GPS, then you should test what happens when the resource or resources are not available •  For example, if your application uses the network, it can notify the user if access is unavailable, or disable network-related features, or do both
  • 38. References •  •  •  •  •  •  •  •  •  http://stackoverflow.com/questions/2961049/effective-android-programmingtechniques http://www.curious-creature.org/2009/02/22/android-layout-tricks-1/ http://www.curious-creature.org/2012/12/01/android-performance-case-study/ http://developer.android.com/training/improving-layouts/optimizing-layout.html http://eclipse.dzone.com/news/effective-eclipse-shortcut-key http://developer.android.com/tools/testing/what_to_test.html http://developer.android.com/tools/publishing/preparing.html http://stackoverflow.com/questions/9494037/how-to-set-text-size-of-textviewdynamically-for-diffrent-screens http://developer.android.com/training/basics/supporting-devices/screens.html
  • 39. Thank you Kanda Runapongsa Saikaew •  Khon Kaen University, Thailand •  •  •  •  •  Assistant Professor of Department of Computer Engineering Associate Director for Administration of Computer Center [email protected] Twitter: @krunapon G+: https://plus.google.com/u/0/118244887738724224199