Design and build apps the right way. Learn how to create apps that look great and perform well on as many devices as possible, from phones to tablets and more
Avoid creating objects unless you really need to, try reusing Android’s API instead. Creating an object in a “desktop” world is relatively cheap, however in such a resource constraint environment as a mobile phone, it will drastically impact the performance.. not in a good way.
In order to avoid friendly “Force Close” popups from your applications, use Android’s “AsyncTask” which will allow to execute a certain activity in background:
DownloadFilesTask AsyncTaskURL, , Long
i i count i
publishProgress i count
read more about AsyncTask in Android Developer Guide
Think about what an absolute minimum amount of updates / syncs you can do, and stick to this minimum. This will greatly improve battery life as well resource usage by the application.
Only use a WakeLock when you need one with as minimum level as possible: PARTIAL_WAKE_LOCK, SCREEN_DIM_WAKE_LOCK, FULL_WAKE_LOCK. Here is more aboutPowerManager
Respect a “Back” button: make sure it actually brings user back to a previous state rather than to another state of the application’s flow.
Always check whether “data transfer” is enabled on a device, before attempting to transfer data:
ConnectivityManager cm ConnectivityManager getSystemService .
this is especially important while roaming, when that “twitter update” can cost user a lot. So do respect user settings.
Don’t use undocumented ( not officially supported ) APIs => Next Android release your app is going to break.
Respect and use an application lifecycle:
read more about Android Application Lifecycle
Externalize resources: localization / optimized layouts / strings / array of strings / etc.. Android compiles them into a list of internal resources by assigning an integer ID to each of them, hence making it “cheaper” at runtime, and easier to change => since they are defined in a single location. Here is an example of auto generated ( random layout ) resources:
Think of hiring or delegating UI to people who are designers. Beauty is important
Be resolution independent. Check out “layoutopt” and “hierarchyviewer” that come with Android SDK under “tools”. They help analyzing and optimizing layouts.
Consider using a “non sticky” services when appropriate:
onStartCommand Intent intent, flags, startId
this is useful for services that are going to be executed on a regular basis. So when you are pulling for updates every 10, 15 minutes, it is ok if one of such updates is missed in favor to a healthy resource management
Do not use foreground services unless you absolutely need to.
And if you do use foreground services, use an ongoing notification ( which, starting from Android 2.0, used automatically, if a service is started as a foreground one, but just to keep something in mind to be used for older OS versions )
Kill your own services via stopSelf():
prtoceted onPostExecute result
Now, with this in mind, go and Rock That Android Space!