Android developers are being asked to build proper app for the Android platform. You surely might have heard about the battery backup issues on Android devices. This is the reason, several sessions were made at Google I/O 2010 to let the developers know how to make better apps by avoiding these:

1) SLOTH:
Th key to make the best applications on Android. Fast & Responsive.
The Golden Rules Of Performance
Don’t do work that you don’t need to do
Don’t allocate memory if you can avoid it
Responsiveness
The application should’t make user to wait, Android device is a mobile device where the user expect responses pretty faster than the PC which is kept on the desk and the user sits infront waiting for things to happen. So no modal loading on mobile devices because user use the device on the go!
You’ve a five seconds to response to user on user’s action, if not then your app fails right there. To avoid this, you need to process the request of the user in background, in another thread so that the UI thread be active and doesn’t runs into unresponsive mode. We usually do this using Java’s traditional Threads through making UI Thread separate and other for processing the request in background and both need to get sync as each thread experience any change, but Android has it’s own Class which takes care of it right away and reduces this huge lines of code in your source code. This Class is called “Async Task”, the following is the sample code:


protected void doInBackground(Void… arg0) {
//Do your time consuming process..
publishProgress();
return null;
}
protected void onProgressUpdate(Void… arg0){
}
protected void onPostExecute(Void result){
}

2)GLUTTONY
The only worse thing than having the app that is slow and unresponsive, is an app which makes the system slow and unresponsive and drains all of your battery as well. The key is to always use the system resources in responsibly. So, to avoid being a bad developer all you want to do is make sure you are being very respectful of power. Don’t use power until you absolutely have to. Don’t do updates too often than you need to, either. The followings are Don’ts and Dos:
Don’ts
Don’t’ use over WakeLocks
Don’t update Widgets too freequestly
Don’t’ update your location unnecessarily
Don’t use Services to try to override users or the system
Dos
DO share data to minimize duplication
DO use Receivers and Alarms not Services and Threads
DO let users manage updates
DO minimize resource contention
What is WakeLock?
-It force the CPU to keep running
-It force the screen to stay on (or stay bright)
-It Drains your battery quickly and efficiently

PowerManager pm = (PowerManager)getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "My Wakelock");

Do you really need to use one?
Use the minimum level possible and consider which property is suitable for your need,


PARTIAL_WAKE_LOCK

SCREEN_DIM_WAKE_LOCK

SCREEN_BRIGHT_WAKE_LOCK

FULL_WAKE_LOCK

  • Release as soon as you can
  • Specify a timeout
  • Don’t use them in Activities, instead use them in Window


wl.acquire(10000);
//Screen and power stays on
wl.release();

3)HOSTILITY
Don’t make user pull out the battery out of their devices.. Don’t drain the power.
“Doing what the user aspects with respect to navigation flow is absurdly important for overall user satisfaction.”
  • -User experience should be your top priority
  • -Respect user expectations for navigating your app
  • -The back button should always navigate back through previously seen screens
  • -Always support trackball navigation
  • -Understand your navigation when try point is o notification or widget
  • -Navigating between application elements should be easy and intuitive
  • -Don’t hijack the native experience
  • -Don’t hide the status bar
  • -Back button should always navigate through previous screens
  • -Use native icons consistently
  • -Don’t override the menu button
  • -Put menu options behind the menu button
  • -Respect user preferences
  • -Use only enabled location-based services
  • -Ask permission before transmitting location data
  • -Only transfer data in the background if user enables


ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
boolean backgroundEnabled = cm.getBackgroundDataSetting();

4)ARROGANCE
  • -Don’t fight with System, mean don’t use unofficial documented APIs
  • -Undocumented APIs will gonna be breached by Google in next update. Think about it before using it.
  • -Make your app behave consistently with the system
  • -Respect the application lifecycle model: on pour on start. saving data saving cache
5)DISCRIMINATION



There are just so many architectures that Android OS supports, that easily can’t be guessed. Android OS supports almost all the major hardware architecture. If you taget at any one type of device you might miss the 2/3 of market. Try centralizing resources, like images and strings, etc. that will help you maintain the resources for all different devices available ion market. It also helps in Internationalizing your application.

One Response to “Five deadly sins that Android Developers should avoid”

  1. HTTP://Www.Gearheadmom.Com/Member/15283/ Says:

    HTTP://Www.Gearheadmom.Com/Member/15283/…

    Android Developers | Android Apps Developers | Android Application Development…

Leave a Reply

You must be logged in to post a comment.

HostGator.com for easy WordPress hosting