Exploring Android Studio: Advanced Features


Larry Schiefer

Welcome to Part 9 of this review of the Pluralsight course Exploring Android Studio by Larry Schiefer.

Larry Schiefer is the CTO and co-founder of HiQES, a mobile, embedded, and application development service company. Larry has over 16 years of experience leading teams, and designing and developing high performance and robust software, and is a Google GDE.

Advanced Features

Refactor Support

Android Studio gives us easy to use refactoring support.

In Java we can:
– rename classes
– move classes within package or to another package
– push methods up
– extract into methods
– change signatures
– Extract into new class or interface

It extends beyond Java and also supports XML, allowing us to refactor styles, layouts and values.

If you’ve used JetBrains ReSharper before, this functionality should be very familiar to you.

Larry moves a class to an upper level and renames it. We see there’s a button where we can preview the changes.
When we click on it, a new Refactoring Preview tool pane is opened. This shows us all the changes in a tree-like format.

If we agree with these changes we can click the “Do Refactor” button to apply them.

Code Analysis

Android Studio offers:

– In-line Analysis
– Use of Lint for code / XML and common syntactic and other issues. Automatically run when building a release package.
– Analyse code dependencies
– Analyse the data flow through our code. View the way methods are called and fields are accessed.
– Analyse a stack trace taken outside of Android Studio.

Larry shows us the results appear as a small yellow square at the top right hand side of Android Studio.
We can summary information by hovering over it.

We also see yellow bands to mark each of the lines where a warning applies.
If we double click of one of these, Android Studio jumps straight to the offending line of code.

Android studio also shows a red band when and where there is an error.

Next, we go to the Analyse menu, choose “Inspect Code…” and inspect the whole project. Results are grouped into the following categories:

– Android
– Android Lint
– Assignment issues
– Class structure
– Code style issues
– Declaration redundancy
– General
– Javadoc issues
– Probable bugs
– Spelling

We also see the “Analyse Stacktrace…” functionality which is found at the bottom of the Analyse menu. We can paste an external stack trace into the window that opens.
There’s a checkbox for automatically detecting and analysing thread dumps copied to the clipboard, and a normalize button which cleans up any mangled text.

When we click OK we see a new pane at the bottom has been activated. We can use the arrow button on the left to navigate up and down the stack.
This makes the editor jump up and down to the relevant lines of interest.

Project Navigation

Features include:

– Show definition
– Show usage
– Find by name
– Find super or overrides
– Examine class hierarchy
– Find related files

Larry shows us many of these features and wraps up by showing us how Android Studio finds files related to other files.

Navigate -> “Related Files…”

Advanced Debug Features

We start by attaching to a running application. Larry runs the app on his Nexus manually, and in Android Studio goes to:

Run->Attach debugger to Android process

The dialog box that opens gives us the ability to see all processes in the system. Larry says this is significantly easier than it is in Eclipse.

The next set of features we learn are in the Android pane, or as it is named in newer versions, Android Monitor.

There’s a screen capture button which gets a screenshot from the device.

Even better than that, the button below requests the device to stream the screen to our development machine for recording.
Wi-Fi needs to be available for this to work and our development machine must be on the same network as our device.

The System Information button has several different options:

– Activity Manager state
– Package Information
– Memory Usage
– Memory use over time
– Graphics State

When we click on “Activity Manager state” the editor pane is updated with a new tab containing the output of the dumpsys.

Larry also covers the “Terminate application” button, which is the fourth button down and shows a red circle with a X in it.
We use this to kill the selected Android application on the attached device.

We also get an explanation of Android Studio’s memory profiling functionality.
For further information on this see StackOverflow and the official docs.

Version Control System Integration

Android Studio includes support for Version Control Integration via VCS plugins and comes bundled with support for the following:

– Git
– Mercurial

There’s a consistent interface for all of these common operations:

– Create a new project from the version control system
– Add / remove files and directories
– Create a new branch
– Merging
– Diff
– History

There’s also support specific to the technology such as stashing in Git and updating in SVN.

We see that the Quick Start menu gives us the option of checking out from Version Control. When we click this we see a list of supported version control systems to choose from.
This list includes GitHub, and this is a wrapper around the normal Git support.

In this lesson we point to Larry’s Android Notifier project.

Once synchronized, we can view this project in Android Studio and see some files are shown in different colored fonts:

Red: Not in the repository, or there is a conflict
Green: File to be added to source control
Blue: local modifications
White/Black: Unchanged, or ignored

Before making any changes, Larry shows us some of the available features for Git.

In the VCS menu, click on the Git submenu. This shows a number of common operations:

– Commit Directory…
– Add
– Compare with Branch..
– Show History
– Revert…
– Branches
– Tag Files…
– Merge Changes…
– Stash Changes…
– Unstash Changes…
– Reset HEAD…
– Fetch
– Pull…
– Push…
– Rebase…
– Rebase my GitHub fork
– Create Pull Request

If you are new to Git see Using Git With a GUI.

In this lesson we create a new branch “dev_status_ticker” and a green bubble appears above the changes tool pane.

If we open this we see the current changes which are project related files.

If we change from the Local tab to the Log tab, we see the Git revision history.

Green represents a local branch and purple represents a remote branch.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s