This is a mirror of official site: http://jasper-net.blogspot.com/

Effective Android Programming Techniques

| Wednesday, November 23, 2011
Here's my personal top twenty. I use this in addition to the usual lists from d.android.com. I could add another five, though the list is long enough.

    Add Two Numbers: Your first non-tutorial application should be to take two numbers and add them together. It sounds too simple. You will spend some hours getting the layouts, the callbacks, and onPause/onResume to work correctly. Do it.
    It is Java: You work in Java for most of your Android programming. Don't spend time praising it. Don't spend time complaining about it. Just work with it.
    Love RelativeLayout: Most of the tutorials use LinearLayout, but you will find that RelativeLayout is truly useful. Many layouts, like the GridLayout aren't used much at all. Play around with RelativeLayout. See an example from this question.
    Use fill_parent with a top level RelativeLayout: A surprisingly common and hard to find problem is putting a wrap_content in a top level RelativeLayout and then wondering why unrelated fields far down in the hierarchy are rendering strangely.
    Use empty layout items: You will often use empty items in your layouts just for positioning other layouts. For example, you might use an empty TextField, of width=0 and height=0 and centerInParent='True' just to anchor things relative to the middle of the screen. Also, you might have an empty TextField or LinearLayout so that you can give a layout_weight=1 to it and have it take up more screen space.
    Set a layout background color: If you are having trouble figuring out your layout, try setting the background colors on some objects. It can highlight your mistakes faster than other tools, and shows some surprises that the IDE red box doesn't always help.
    Download Apps-For-Android: This is a big chunk of useful source code for a half dozen applications. It can supplement the sample applications nicely and show different coding style solutions. Grab it using svn co http://apps-for-android.googlecode.com/svn/trunk/ apps-for-android-read-only
    Download the source: You need the Android source to solve some problems or, more likely, get past holes in the documentation. Your copy does not need to be perfect or kept up to date. You can learn to use the repo command, or just visit http://android.git.kernel.org/ for a snapshot.
    Learn to search your source: The fastest solution to many problems is to find where a particular parameter is used in some other source. Put a copy or link to the sample applications, apps-for-android applications, and any other source you have under one directory tree. Use "grep -ir funky_parameter sample_code/" or your favorite searching routine to quickly find some code that uses that parameter.
    Use Eclipse: Even you have a favorite editor or IDE you have used for years, use Eclipse for Android development. It is good enough as an IDE and is really part of the development tools suite. Any time you spend trying to jury-rig your IDE to work is time you didn't code.
    Learn Eclipse: Learn a few new tricks with Eclipse every day. Some of my favorite commands were found reading this list and this question.
    Get help when starting out: The quantity of readable material can be overwhelming. Setting up the environment can be tricky. Going to an Android Meet-up or users group can help get over the initial hump.


Read more: Stackoverflow
QR: effective-android-programming-techniques

Posted via email from Jasper-net

0 comments: