What’s New in Android Studio 2.0

Android Studio 2.0 was just released – take a quick tour of what’s new! By Huyen Tue Dao.

Leave a rating/review
Save for later
Share

In the last quarter of 2015 Google announced a brand new, Android-centric conference called the Android Dev Summit. Google kept the conference content secret, promising “deep technical sessions,” but dropped huge hints about something new for Android Studio.

Sure enough, the big superstar of the Android Dev Summit (other than the platform and tool engineers) was Android Studio 2.0. The Android team buffed and polished the interface nicely; what’s more, clearly the Android Tools Team felt the need for speed, as they have increased the speed and performance of builds and the Android Emulator, which has also earned a shiny “2.0” badge.

On April 7, Google released Android Studio 2.0 in their “stable” channel, so it’s no longer just a preview, but the new standard for Android development! In this article, you will learn about the improvements Android Studio 2.0 has to offer, and will try out a few of them.

If you’re brand new to Android Development, you should work through the Android Tutorial for Beginners. In particular, you should be able to set up and run Android Studio and the Android Emulator. If you need some help with that, look at the Beginning Android Development Tutorial: Installing Android Studio.

Alright, let’s take Android Studio 2.0 for a test drive!

Getting Started

First, download the companion project for this article. It’s a complete Android project for you to use on your test drive. There are a few places where you will modify code, but just as part of demoing new Android Studio features.

Launch Android Studio, and in the Welcome to Android Studio dialog, select Import project (Eclipse ADT, Gradle, etc.).

Android Studio: Welcome to Android Studio

Choose the top-level directory of the companion project and click OK.

Select companion project

If you look through the project, you should see two activity classes and two RecyclerView view holder classes, along with the accompanying resource and layout files. Don’t worry too much about the details; you won’t be heavily editing these files.

Build and run. You should see this:

First build of companion app

The top card has a few widgets—you’ll get to play with those later. Below the widgets, you should see helpful links for further reading on some of the material covered in this article.

Improved IDE

Just because you’re an Android developer who makes fantastic UIs doesn’t mean you don’t crave ways to make even more fantastic UIs. Android Studio 2.0 feeds your craving, including several UI improvements and new tools for you to enjoy.

IntelliJ Features

Google based Android Studio on Jetbrains IntelliJ IDEA. While the two IDEs have different companies and development teams, they do import features from each other, which is great news as IntelliJ is packed with useful tools for code navigation, code inspection, and refactoring. In fact, Android Studio 2.0 already comes with new features from the newest (as of this article’s publication) release of IntelliJ, version 15.

One new feature is the instant results in the Find in Path action. Let’s try it out!

In Android Studio, select Edit \ Find \ Find in Path (or use the keyboard short CMD+Shift+F). In the Find in Path window that appears, select the Preview tab. Enter any search text in the Text to find field. For search results to appear in the Preview tab, make sure the Regular expressions checkbox in the Options tab is not checked.

Live Preview of Text Search

The search results should update in real time as you type. These results also utilize any options you set on the Options tab, giving full search power to even the most impatient.

A handy new code inspection tool from IntelliJ 15, Expression Type, helps out when you cannot immediately tell or remember the resulting type of an expression.

To see it in action, highlight an expression in your code and hit CTRL+Shift+P.

Using Expression Type

This determines the type of the expression’s value and displays it in a tooltip. Sweet!

You can learn more about the newest IntelliJ 15 features (that you get to use from Android Studio) from Jetbrains.

Deep Links Integration

In your app, you can enable deep links that allow your app to appear in relevant Google search results. You create these deep links via intent filters for handling certain URLs. If you are not familiar with intent filters, check out our Android: Intents Tutorial.

Android Studio 1.5 already povided an easy method to generate these intent filters in your Android Manifest, but Android Studio 2.0 adds static analysis that verifies whether your app is ready for app indexing.

To give it a try, open AndroidManifest.xml in Android Studio.

You should see the following:

<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.raywenderlich.as20allthethings"
          xmlns:android="http://schemas.android.com/apk/res/android">

  <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

  <application
      android:allowBackup="true"
      android:icon="@mipmap/ic_launcher"
      android:label="@string/app_name"
      android:supportsRtl="true"
      android:theme="@style/AppTheme">

    <activity android:name=".MainActivity">
      <intent-filter>
        <action android:name="android.intent.action.MAIN"/>
        <category android:name="android.intent.category.LAUNCHER"/>
      </intent-filter>
    </activity>

    <activity
        android:name=".DeepLinkActivity"
        android:theme="@style/AppTheme.Green"/>

  </application>

</manifest>

Right-click on the activity android:name=".DeepLinkActivity" tag, and in the context menu that appears, select Generate \ URL.

Add a Deep Link Intent Filter: Context Menu

Alternatively, click on the tag and hit Option+Enter; in the pop-up that appears, select Add URL.

Add a Deep Link Intent Filter:  Generate

Using either method tells Android Studio to generate the necessary intent filter. The activity should now look like this:

<activity
    android:name=".DeepLinkActivity"
    android:theme="@style/AppTheme.Green">
  <!-- ATTENTION: This intent was auto-generated. Follow instructions at
https://g.co/AppIndexing/AndroidStudio to publish your URLs. -->
  <intent-filter>
    <action android:name="android.intent.action.VIEW"/>

    <category android:name="android.intent.category.DEFAULT"/>
    <category android:name="android.intent.category.BROWSABLE"/>
    <!-- ATTENTION: This data URL was auto-generated. We recommend that you use the HTTP scheme.
      TODO: Change the host or pathPrefix as necessary. -->
    <data
        android:host="as20allthethings.raywenderlich.com"
        android:pathPrefix="/deeplink"
        android:scheme="http"/>
  </intent-filter>
</activity>

As you can see, Android Studio did most of the work here in setting up the intent filter so that any URLs that match “http://as20allthethings.raywenderlich.com/deeplink” will be handled by this app.

To see the Android Studio 2.0 static analysis in action, change the data tag to look like the following:

<data
    android:host="as20allthethings.raywenderlich.com"/>

Now you should see Android Studio 2.0 complaining that you did something a little bad.

Deep Link Lint error

Here, Android Studio specifically warns you that Google search will not play nice with this invalid URL. Undo those changes to make Android Studio and your app happy again.

You may feel that the improvement is small, but app indexing is a powerful tool, and integrating with Google Search will increase the visibility and utility of your app. For more information on app indexing, check out this overview from Google Developers.

Huyen Tue Dao

Contributors

Huyen Tue Dao

Author

Over 300 content creators. Join our team.