10 Helpful Hints for Android Application Development

By Michael Burton

Part of Android Application Development For Dummies Cheat Sheet

Although 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.

  • Understand the Activity lifecycle and Fragment lifecycle.

    You will use them over and over, and a thorough understanding can help avoid baffling problems later.

  • 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 their screen).

  • 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.

    The Android Developer website provides a list of common tasks and instructions on how to perform them.

  • If you’re not sure what a package or class does, you can quickly identify its purpose.

    You can place your cursor over the object or class while inside Android Studio and press Ctrl+J to view the documentation pop-up window. If no tooltip exists, you can view the documentation online at Android Developer Reference.

  • You can quickly find all references of a particular object.

    You can do this in your class file by selecting the object and press Alt+F7.

  • You can make the stream messages in the logcat window more readable.

    You do so by creating a filter that specifically applies to your application logging. You may also find pidcat to be helpful.

  • Many errors have a quick fix.

    Go to the error and then press Alt+Enter to get the quick-fix menu. This can be a handy way to add new fields and methods. For example, you can type the name of a getter that does not yet exist, press Alt+Enter, and then choose Create Getter to have the method created for you automatically.

  • It’s easy to quickly navigate around a project.

    To do so, press Shift twice rapidly and start typing the name of the thing you’re interested in. It can be a file, type, member, local variable, or just about anything. Select it from the pop-up list and press Enter.

  • To quickly run your Android application, press Ctrl+R.