Saturday, January 26, 2013

Check List When Coding with Android


When I am dealing with android coding, I always forget some important issues, therefore the app tends to cash.

So I decided to list those things, and do the finishing check after I wrote every lines.



  • Network Connection
You should always keep in mind that the network connection may be down in some situations, such as turning cellphone into airplane mode, going through a tunnel or travelling to some desolate places. So check the connection before starting any network operation.
  • DB Connection
This issue also apply to other kinds of development besides Android, add try-catch block if necessary.
  • UI Threads or Background Ones
If you call a UI operation within a background thread, the app will crash; if you call a time-consuming thread(such as retrieving data from Internet) within a UI thread, app may become unresponsive and keep user waiting.
  • Null-pointer Exception
This issue also apply to other kinds of development besides Android.
  • ClassCastException
This issue also apply to other kinds of development besides Android. Just remember to use 

if(object instanceof [ClassName])
before you converting the object to certain type of class(if you are not absolutely sure this object is of the same type).
  • Bmp Operation with Out of Memory Exception
Since most cellphones have limited memory, you need to be more careful with picture operations. Therefore, Android encourages us using BitmapFactory.decodeFile / decodeFilepath / decodeStream instead of BitmapFactory.createBitmap. Also remember to add try-catch block if necessary.