Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pitfalls of Android applications

Tags:

android

Are there pitfalls or the points to remember while programming for Android? I think the list will include topics on Multithreading, Persistent Storage, etc.

like image 684
Prabhu R Avatar asked Aug 24 '09 13:08

Prabhu R


2 Answers

There are many things that could be said here.

The Android videos from Google I/O 2009 cover most of the aspects that should be kept in mind, when programming on Android. In fact, the http://android-developers.blogspot.com/ articles are the source, on which these presentations expand, and seeing them explained from some of the best Google engineers (and as a bonus you'll get a Q&A section) is a must for every Android developer, IMO.

Some of the things that could be mentioned:

  • Don't use floats, when you can achieve similar results with integers, because Android doesn't have native support for floating point values.

  • Use the debugging tools extensively, to optimize both performance and maintainability, and to avoid common pitfalls like ViewGroup redundancy in UI design, or unnecessary multiple calls to heavier methods (View.inflate(), findViewById(), setImageResource()).

  • Bundle your background service calls, otherwise you are waking up the OS unnecessarily and too often, while risking other services piggy-backing your call (which results in severely reduced battery life)

  • Prefer SAX-parsers over DOM-parsers, you lose time while implementing them, but you win time in your app's performance (and your device's availability)

  • Keep your UI manipulations on your UI thread, because the interface toolkit is not thread-safe

  • Keep in mind that orientation change destroys and creates your Activity again (I learned that the hard and painful way - this is how I started to follow the android-developers' blog)

...and many others.

like image 51
Dimitar Dimitrov Avatar answered Oct 04 '22 02:10

Dimitar Dimitrov


Android Developers has good post about avoiding memory leaks due to keeping Context references. There are a lot of other interesting posts there too.

like image 39
jstevej Avatar answered Oct 04 '22 02:10

jstevej