Some of you (or should I say some of my followers - @cyrilmottier) may have noticed I have been tweeting several tips dealing with Android development lately. I received a lot of great feedback about those tips and I would like to thank everybody for their support. Some people also asked me to make a blog post gathering together all of the Android dev tips I have tweeted; so here it is.. Starting from now, I will try to update this article as soon as I tweet a new tip. Have fun with these tips and feel free to use the comment system at the bottom of this page if you have any question.
25 May 2012: Null your ViewStub references after being inflated (mViewStub = null). It lets the GC garbage it and saves memory. #androidtip #androiddev
9 May 2012: #androidtip (for experts): Create custom Views with some texts in it using Layout (http://developer.android.com/reference/android/text/Layout.html) and its subclasses. #androiddev
4 May 2012: #androidtip: When working with ContentProviders you often have to play with Uris. ContentUris is here to help you (http://developer.android.com/reference/android/content/ContentUris.html)
2 May 2012: #androidtip: Need a “triplean” in your code (a boolean with 3 possible values : unknown, true and false)? Use a Boolean (null, true, false)
30 Apr 2012: #androidtip: Starting API 11, you can draw dividers between your Views in a LinearLayout (http://developer.android.com/reference/android/widget/LinearLayout.html#setShowDividers(int))) #androiddev #android
25 Apr 2012: #androidtip: If you want to know if an URL is valid, HTTP, HTTPS, etc. use the android.webkit.URLUtil (http://developer.android.com/reference/android/webkit/URLUtil.html) class
25 Apr 2012: #androidtip: Starting from API 11 you can reuse Bitmap (using BitmapFactory#Options#inBitmap) in order to avoid memory allocations.
24 Apr 2012: #androidtip When displaying web content in a Fragment you can use the WebViewFragment: a Fragment managing a WebView. #androiddev
19 Apr 2012: Use android:foreground on your FrameLayout to overlay a
Drawable on opaque images in itemviews 18 Apr 2012: Check whether a View is actually visible using View#isShown(). It will check your View visibility AND all of its ancestors
17 Apr 2012: Remember you can start the Settings app from yours on a given screen using the actions described in http://developer.android.com/reference/android/provider/Settings.html
16 Apr 2012: Pre-populate Intent chooser using LabeledIntents (Intent with a name/icon) and the Intent#EXTRA_INITIAL_INTENTS extra
13 Apr 2012: When creating your own custom view with scrollable content, don’t forget to use EdgeEffect (http://developer.android.com/reference/android/widget/EdgeEffect.html)
12 Apr 2012: Need View#onConfigurationChanged on API < 8? Use a BroadcastReceiver or forward your Activity’s onConfigurationChanged. Here’s a sample of using a BroadcastReceiver: http://gist.github.com/2367432
11 Apr 2012: Stop uselessly fetching resources when your WebViews aren’t visible anymore with WebView#onPause|onResume (API >= 11)
11 Apr 2012: With split content (ListView + content), call setActivated(true) on the appropriate item view to indicate the current section
10 Apr 2012: Don’t forget to use android:textIsSelectable=“true” (API >= 11) on your TextView to let users copy your TextView content
6 Apr 2012: Java 5 accepts return type refinement. Return your object type instead of Object in Adapter#getItem(int). It saves you a cast
4 Apr 2012: Do not forget to call HandlerThread.quit() (or HandlerThread.getLooper().quit() if API < 5) when you no longer need it
3 Apr 2012: Stop developing countdown algorithms, use the built-in CountDownTimer (http://developer.android.com/reference/android/os/CountDownTimer.html) #android #androiddev
2 Apr 2012: Add margins to your ListView selection areas using a SelectionBoundsAdjuster (http://developer.android.com/reference/android/widget/AbsListView.SelectionBoundsAdjuster.html) #android #androiddev