Android Application Development For Dummies
Developing Android applications calls for familiarity with a development environment, an SDK, emulators, and the Android platform. Immersing yourself into the various screen sizes, framework intricacies, and dependencies can leave your head spinning. Here are some helpful hints to get you through your day-to-day development experience.
Helpful Hints for Android App Development
While solving problems with Android is a simple task, you may get to the point in app development where you're not sure what to do. The following list should point you in the right direction when you’re in need of help.
Not sure how to solve a particular problem? Visit the forums at StackOverflow.com and use the Android tag. StackOverflow is an Android platform–recommended destination for developer questions.
The most common tasks have already been done for you. A list of common tasks and instructions on how to do them are provided by the Android developer website.
If you’re not sure what a package or class does, place your cursor over the object or class while inside Eclipse to view the documentation pop-up window. If no tool tip exists, you can view the documentation online at Android Developer Reference.
Understand activity and fragment lifecycles. You use them over the course of your development career, and a thorough understanding can help avoid problems.
Remember that you are responsible for saving and restoring instance states in activities and fragments. If you create a member variable in an activity or fragment, make sure you save it in onSaveInstanceState() and restore it using the bundle in onCreate(). Failing to do so can make your activity or fragment appear to work most of the time, but randomly fail in other situations (such as when a user rotates the screen).
To make the stream messages in the DDMS perspective more readable, create a filter that specifically applies to your application logging.
When typing into Eclipse, you sometimes know the name of the destination property, method, or class you’d like to create. However, it does not yet exist. Type the name in the component, Eclipse will inform you that the component cannot be found. Now select it, and press F2. This gives you a small pop-up window that allows you to create through the click of a button.
To quickly navigate around a class file, press Ctrl+O and start typing the name of the member you’re interested in. Select it from the pop-up list and press Enter.
Useful Eclipse Keyboard Shortcuts for Developing Android Apps
You’ll most likely spend most of your Android development career in the Eclipse IDE. The following table shows a few keyboard shortcuts that can help you save a lot of time.
|Create a new file in the current package||Alt+Shift+N|
|Organize the import statements||Ctrl+Shift+O|
|Navigate to the source definition||F3|
|Rename an object||Alt+Shift+R|
|Search through Java files||Ctrl+H|
|Jump to a particular type||Ctrl+Shift+T|
|Find references to a select object||Ctrl+Shift+G|
|Navigate left||Alt+left-pointing arrow|
|Navigate right||Alt+left-pointing arrow|
|Navigate among the tabs||Shift+Page Up or Shift+Page Down|
|Run your app||Ctrl+Shift+F11|
Common Android Intent Usage
You’ll use a few basic intents most of the time while developing apps for Android. The following table shows you the code for several basic Android intents.
|Start an activity||startActivity(new Intent(this, Destination.class));|
|Create a chooser||Intent.createChooser(yourIntent, "Please Select");|
|Open the web browser||Intent i = new
|Start activity for a result||startActivityForResult(yourIntent, YOUR_REQUEST_CODE);|
Developing Applications for Multiple Screen Sizes in Android
One of the challenges that you will encounter during your time as an Android app developer is developing for multiple screen sizes. There are many things to keep in mind during your adventure into screen sizes. The following list can keep you on track.
The size requirements for each icon in each density vary for each type of icon. You find launcher icons, menu icons, status bar icons, tab icons, and many more. They are all built differently for each screen density. When building these icons, reference the Android Icon Design Guidelines.
Try to always use the density-independent pixel (dip or dp) measurement unit for views and the scale-independent pixel (sip or sp) for font sizes when defining your user interface. This helps your application scale to different devices. The density-independent pixel is a virtual pixel that scales proportionally for each given screen density.
Provide the supports-screens element to the AndroidManifest.xml file to help the Android market determine whether your application is compatible with various screen sizes.
Provide graphics for extra-high-, high-, medium-, and low-density devices. While this may increase your development and design time, it greatly improves the usability and appearance of your application.
Use fragments liberally to make supporting tablet devices easier.