diff --git a/docs/html/training/basics/firstapp/building-ui.jd b/docs/html/training/basics/firstapp/building-ui.jd index a680c733f99e7..6f321e990ce5d 100644 --- a/docs/html/training/basics/firstapp/building-ui.jd +++ b/docs/html/training/basics/firstapp/building-ui.jd @@ -71,17 +71,17 @@ android.view.View} objects.

Create a Linear Layout

    -
  1. From the res/layout/ directory, open the - activity_main.xml file. +
  2. In Android Studio's Project window, open app > res > + layout > activity_main.xml.

    This XML file defines the layout of your activity. It contains the default "Hello World" text view.

  3. When you open a layout file, you’re first shown the design editor in the Layout Editor. For this lesson, - you work directly with the XML, so click the Text tab to switch to - the text editor. + you work directly with the XML, so click the Text tab at the bottom + of the window to switch to the text editor.
  4. -
  5. Replace the contents of the file with the following XML: +
  6. Delete everything and insert the following XML:
    <?xml version="1.0" encoding="utf-8"?>
     <LinearLayout
         xmlns:android="http://schemas.android.com/apk/res/android"
    @@ -138,6 +138,9 @@ href="{@docRoot}guide/topics/ui/declaring-layout.html">Layout guide.

    </LinearLayout>
    +

    Don't worry about the error that appears for +@string/edit_message; you'll fix that soon.

    +

    Here is a description of the attributes in the {@link android.widget.EditText <EditText>} you added:

    @@ -157,7 +160,7 @@ XML. It is followed by the resource type ({@code id} in this case), a slash, the

    A resource object is a unique integer name that's associated with an app resource, such as a bitmap, layout file, or string.

    Every resource has a -corresponding resource object defined in your project's {@code gen/R.java} file. You can use the +corresponding resource object defined in your project's {@code R.java} file. You can use the object names in the {@code R} class to refer to your resources, such as when you need to specify a string value for the {@code android:hint} @@ -174,7 +177,7 @@ href="{@docRoot}guide/topics/resources/providing-resources.html">Providing Resou

    The plus sign (+) before the resource type is needed only when you're defining a resource ID for the first time. When you compile the app, the SDK tools use the ID name to create a new resource ID in -your project's {@code gen/R.java} file that refers to the {@link +your project's {@code R.java} file that refers to the {@link android.widget.EditText} element. With the resource ID declared once this way, other references to the ID do not need the plus sign. Using the plus sign is necessary only when specifying a new resource ID and not @@ -211,10 +214,10 @@ the same name does not cause collisions.

    Add String Resources

    By default, your Android project includes a string resource file at -res/values/strings.xml. Here, you'll add two new strings.

    +res > values > strings.xml. Here, you'll add two new strings.

      -
    1. From the res/values/ directory, open strings.xml.
    2. +
    3. From the Project window, open res > values > strings.xml.
    4. Add two strings so that your file looks like this:
      <?xml version="1.0" encoding="utf-8"?>
       <resources>
      @@ -340,15 +343,12 @@ android.widget.LinearLayout}.

      Run Your App

      -

      This layout is applied by the default {@link android.app.Activity} class -that the SDK tools generated when you created the project.

      - -

      To run the app and see the results, - click Run 'app' +

      To see how the app now looks on your device or emulator, + click Run in the toolbar.

      -

      Continue to the next -lesson to learn how to respond to button presses, read content -from the text field, start another activity, and more.

      \ No newline at end of file +

      To add app behaviors such as responding to a button and starting +another activity, continue to the next +lesson.

      \ No newline at end of file diff --git a/docs/html/training/basics/firstapp/creating-project.jd b/docs/html/training/basics/firstapp/creating-project.jd index cad32bf077d87..60be5f6a3ab42 100644 --- a/docs/html/training/basics/firstapp/creating-project.jd +++ b/docs/html/training/basics/firstapp/creating-project.jd @@ -31,129 +31,71 @@ next.link=running-app.html
      1. In Android Studio, create a new project:
          -
        • If you don't have a project opened, in the Welcome screen, click - New Project.
        • -
        • If you have a project opened, from the File menu, select New - Project. The Create New Project screen appears.
        • +
        • If you don't have a project opened, in the Welcome to Android Studio window, click + Start a new Android Studio project.
        • +
        • If you have a project opened, select File > New Project.
      2. -
      3. Fill out the fields on the screen. For Application Name - use "My First App". For Company Domain, use "example.com". - For the other fields, use the default values and click Next -

        Here's a brief explanation of each field:

        +
      4. In the New Project screen, enter the following values:

          -
        • Application Name is the app name that appears to users.
        • -
        • Company domain provides a qualifier that will be appended to the package - name; Android Studio will remember this qualifier for each new project you create.
        • -
        • Package name is the fully qualified name for the project (following the - same rules as those for naming packages in the Java programming language). Your package name - must be unique across all packages installed on the Android system. You can - Edit this value independently from the application name or the company - domain.
        • -
        • Project location is the directory on your system that holds the project - files.
        • +
        • Application Name: "My First App"
        • +
        • Company Domain: "example.com"
        +

        Android Studio fills in the package name and project location for you, + but you can edit these if you'd like.

      5. -
      6. Under Target Android Devices, accept the default values - and click Next. -

        The Minimum Required SDK is the earliest version of Android that your app supports, - indicated using the +

      7. Click Next.
      8. +
      9. In the Target Android Devices screen, keep the default values and + click Next. +

        The Minimum Required SDK is the earliest version of Android that your app supports, + which is indicated by the API level. To support as many devices as possible, you should set this to the lowest version available that allows your app to provide its core feature set. If any feature of your - app is possible only on newer versions of Android and it's not critical to the app's core - feature set, you can enable the feature only when running on the versions that support it (as - discussed in + app is possible only on newer versions of Android and it's not critical to the core + feature set, enable that feature only when running on the versions that support it (see + Supporting Different Platform Versions).

      10. -
      11. Under Add an Activity to Mobile, select Empty +
      12. In the Add an Activity to Mobile screen, select Empty Activity and click Next.
      13. - - -
      14. Under Customize the Activity, accept the default values +
      15. In the Customize the Activity screen, keep the default values and click Finish.
      -

      Your Android project is now a basic "Hello World" app that contains some default files. Take a -moment to review the most important of these:

      +

      After some processing, Android Studio opens and displays a "Hello World" app +with default files. You will add functionality to some of +these files in the following lessons.

      + +

      Now take a moment to review the most important files. First, be sure that +the Project window is open (select View > Tool Windows > Project) +and the Android view is selected from the drop-down list at the top. +You can then see the following files:

      -
      app/src/main/java/com.example.myfirstapp/MainActivity.java
      +
      app > java > com.example.myfirstapp > MainActivity.java
      This file appears in Android Studio after the New Project wizard finishes. It contains the class definition for the activity you created earlier. When you build and run the app, the {@link android.app.Activity} starts and loads the layout file that says "Hello World!"
      -
      app/src/main/res/layout/activity_main.xml
      +
      app > res > layout > activity_main.xml
      This XML file defines the layout of the activity. It contains a {@code TextView} element with the text "Hello world!".
      -
      app/src/main/AndroidManifest.xml
      +
      app > manifests > AndroidManifest.xml
      The manifest file describes the fundamental characteristics of the app and defines each of its components. You'll revisit this file as you follow these lessons and add more components to your app.
      -
      app/build.gradle
      + +
      Gradle Scripts > build.gradle
      Android Studio uses Gradle to compile and build your app. There is a build.gradle file for each module of your project, as well as a build.gradle file for the entire - project. Usually, you're only interested in the build.gradle file for the module, - in this case the app or application module. This is where your app's build dependencies - are set, including the defaultConfig settings: -
        -
      • compiledSdkVersion is the platform version against which you will compile - your app. By default, this is set to the latest version of Android available in your SDK. - By default, this is set to the latest version of Android SDK installed on your - development machine. - You can still build your app to support older versions, but setting this to the latest - version allows you to enable new features and optimize your app for a great user experience - on the latest devices.
      • -
      • applicationId is the fully qualified package name for your application that - you specified in the New Project wizard.
      • -
      • minSdkVersion is the Minimum SDK version you specified during the New Project - wizard. This is the earliest version of the Android SDK that your app supports.
      • -
      • targetSdkVersion indicates the highest version of Android with which you have - tested your application. As new versions of Android become available, you should - test your app on the new version and update this value to match the latest API level and - thereby take advantage of new platform features. For more information, read - Supporting Different - Platform Versions.
      • -
      -

      See Building Your Project with Gradle - for more information about Gradle.

      -
      - -

      Note also the /res subdirectories that contain the -resources for your application:

      -
      -
      drawable-<density>/
      -
      Directories for - drawable resources, other than launcher icons, designed - for various densities. -
      -
      layout/
      -
      Directory for files that define your app's user interface like {@code activity_main.xml}, - discussed above, which describes a basic layout for the {@code MainActivity} - class.
      -
      menu/
      -
      Directory for files that define your app's menu items.
      -
      mipmap/
      -
      Launcher icons reside in the {@code mipmap/} folder rather than the - {@code drawable/} folders. This folder contains the {@code ic_launcher.png} image - that appears when you run the default app.
      -
      values/
      -
      Directory for other XML files that contain a collection of resources, such as - string and color definitions.
      + project. Usually, you're only interested in the build.gradle file for the module. + in this case the app or application module. For more information about this file, + see Building Your Project with Gradle.

      diff --git a/docs/html/training/basics/firstapp/running-app.jd b/docs/html/training/basics/firstapp/running-app.jd index e8098711b9a91..085849fe34d60 100755 --- a/docs/html/training/basics/firstapp/running-app.jd +++ b/docs/html/training/basics/firstapp/running-app.jd @@ -3,9 +3,7 @@ parent.title=Building Your First App parent.link=index.html trainingnavtop=true - page.tags=emulator -helpoutsWidget=true @jd:body @@ -18,7 +16,7 @@ helpoutsWidget=true

      1. Run on a Real Device
      2. -
      3. Run on the Emulator
      4. +
      5. Run on an Emulator

      You should also read

      @@ -34,8 +32,10 @@ helpoutsWidget=true

      In the previous lesson, you created an - Android project. The project contains a default app that displays - "Hello World". In this lesson, you will run the app on a device or emulator.

      +Android project that displays "Hello World." You can now run the app on a real +device or on an emulator. If you don't have a real device available, skip to +Run on an Emulator.

      +

      Run on a Real Device

      @@ -68,7 +68,7 @@ helpoutsWidget=true

      Android Studio installs the app on your connected device and starts it.

      -

      Run on the Emulator

      +

      Run on an Emulator

      Before you run your app on an emulator, you need to create an Android Virtual Device (AVD) @@ -82,12 +82,14 @@ helpoutsWidget=true Tools > Android > AVD Manager, or by clicking the AVD Manager icon in the toolbar.

    5. -
    6. On the AVD Manager main screen, click Create Virtual Device.
    7. -
    8. In the Select Hardware page, select a phone device, such as Nexus 6, - then click Next. +
    9. In the Your Virtual Devices screen, click Create Virtual Device.
    10. +
    11. In the Select Hardware screen, select a phone device, such as Nexus 6, + and then click Next.
    12. -
    13. In the Select Image page, choose the desired system image for the AVD and +
    14. In the System Image screen, choose the desired system image for the AVD and click Next. +

      If you don't have a particular system image installed, + you can get it by clicking the download link.

    15. Verify the configuration settings (for your first AVD, leave all the settings as they are), and then click Finish. diff --git a/docs/html/training/basics/firstapp/starting-activity.jd b/docs/html/training/basics/firstapp/starting-activity.jd index ebf42cbe04382..4385d1304b7f6 100644 --- a/docs/html/training/basics/firstapp/starting-activity.jd +++ b/docs/html/training/basics/firstapp/starting-activity.jd @@ -38,7 +38,7 @@ starts a new activity when the user clicks the Send button.

      Respond to the Send Button

        -
      1. In the file res/layout/activity_main.xml, add the +
      2. In the file res > layout > activity_main.xml, add the {@code android:onClick} attribute to the {@link android.widget.Button <Button>} element as shown below: @@ -52,7 +52,7 @@ starts a new activity when the user clicks the Send button.

        method in your activity whenever a user clicks on the button.

      3. -
      4. In the file java/com.example.myfirstapp/MainActivity.java, +
      5. In the file java > com.example.myfirstapp > MainActivity.java, add the sendMessage() method stub as shown below:
        public class MainActivity extends AppCompatActivity {
        @@ -85,7 +85,9 @@ starts a new activity when the user clicks the Send button.

        Next, you’ll fill in this method to read the contents of the text field and deliver that text to another activity.

        +

        Build an Intent

        +

        An {@link android.content.Intent} is an object that provides runtime binding between separate components (such as two activities). The {@link android.content.Intent} represents an app’s "intent to do something." @@ -113,13 +115,22 @@ another activity.

        } }
        -

        Note: Android Studio will display - Cannot resolve symbol errors because the code references classes - like {@link android.content.Intent} and {@link android.widget.EditText} - that have not been imported. To import these classes, you can either 1) - use Android Studio's "import class" functionality by pressing Alt + Enter - (Option + Return on Mac) or 2) manually add import statements at the top of - the file.

        +

        Android Studio will display Cannot +resolve symbol errors because this code references classes that are not +imported. You can solve some of these with Android Studio's "import class" +functionality by pressing Alt + Enter (or Option + Return on Mac). +Your imports should end up as the following:

        +
        +import android.content.Intent;
        +import android.support.v7.app.AppCompatActivity;
        +import android.os.Bundle;
        +import android.view.View;
        +import android.widget.EditText;
        +
        + +

        An error remains for DisplayMessageActivity, but that's okay; +you'll fix that in the next section. +

        There’s a lot going on in sendMessage(), so let’s explain what's going on.

        @@ -150,6 +161,7 @@ another activity.

        method starts an instance of the DisplayMessageActivity specified by the {@link android.content.Intent}. Now you need to create the class.

        +

        Create the Second Activity

          @@ -169,7 +181,8 @@ another activity.

        1. Creates the corresponding layout file activity_display_message.xml
        2. Adds the required - <activity> + <activity> element in AndroidManifest.xml. @@ -199,7 +212,16 @@ protected void onCreate(Bundle savedInstanceState) { layout.addView(textView); }
        3. -
        4. Press Alt + Enter (option + return on Mac) to import missing classes.
        5. +
        6. Press Alt + Enter (or Option + Return on Mac) to import missing classes. + Your imports should end up as the following: +
          +import android.content.Intent;
          +import android.support.v7.app.AppCompatActivity;
          +import android.os.Bundle;
          +import android.view.ViewGroup;
          +import android.widget.TextView;
          +
          +

        There’s a lot going on here, so let’s explain: