Android Studio for beginners

Android Studio for beginners, Part 4: Debugging tools and productivity plugins

Use built-in tools and plugins to improve code quality and boost productivity in Android Studio

1 2 Page 2
Page 2 of 2

Select Lombok Plugin in the repository list of plugins, then click Install. After Android Studio downloads and installs the plugin, it will prompt you to Restart Android Studio. Restarting activates Lombok Plugin.

A simple example will demonstrate Project Lombok's usefulness. Suppose we add the following minimal Robot class to the example app's W2A.java source file:


class Robot
{
   private String name;
}

The idea with this class is that we'll store the name of the robot being animated and potentially any other information that might be useful, and display this information as a toast (a small message that appears like a tool tip).

We could take a few minutes to add a constructor and getter/setter methods to this code. However, a better option is to let Lombok add this boilerplate for us. Here are the steps:

  1. Right-click on Robot.
  2. Select Refactor from the pop-up menu.
  3. Select Lombok from the next pop-up menu.
  4. Select Default @Data from the next pop-up menu.

You should now observe an @lombok.Data annotation prefixed to the class Robot header. This annotation causes the constructor, getter/setter methods, and other boilerplate code to be auto-generated. You can see all of this boilerplate by repeating the previous steps, but this time select Delombok instead of Lombok. You'll see that Lombok has generated something like the following:


class Robot
{
    private String name;

    public Robot() {
    }

    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public boolean equals(final Object o) {
        if (o == this) return true;
        if (!(o instanceof Robot)) return false;
        final Robot other = (Robot) o;
        if (!other.canEqual((Object) this)) return false;
        final Object this$name = this.getName();
        final Object other$name = other.getName();
        if (this$name == null ? other$name != null : !this$name.equals(other$name)) return false;
        return true;
    }

    protected boolean canEqual(final Object other) {
        return other instanceof Robot;
    }

    public int hashCode() {
        final int PRIME = 59;
        int result = 1;
        final Object $name = this.getName();
        result = result * PRIME + ($name == null ? 43 : $name.hashCode());
        return result;
    }

    public String toString() {
        return "Robot(name=" + this.getName() + ")";
    }
}

Conclusion to Part 4

Android Studio is an amazing (albeit somewhat buggy) environment for developing Android apps. In this short series I've showed you how to download and install Android Studio, walked you through a short Android app-development tutorial, showed you how to build and run your app on a device emulator, and introduced you to a number of useful tools and plugins for Android development.

There's much more for you to learn. For example, you might want to play with Android Profiler to monitor your app's performance and discover any hidden performance bottlenecks. You might also want to install and explore additional plugins to boost your coding productivity.

I hope you'll use Android Studio with both its built-in tools and extensible plugin architecture to develop your Android mobile apps.

1 2 Page 2
Page 2 of 2