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.
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.
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.
This issue also apply to other kinds of development besides Android.
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.