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.
res/layout/ directory, open the
- activity_main.xml file.
+ This XML file defines the layout of your activity. It contains the default "Hello World" text view.
<?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, theA 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.
By default, your Android project includes a string resource file at
-res/values/strings.xml. Here, you'll add two new strings.
res/values/ directory, open strings.xml.<?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-
- 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.
- 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:
+- 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.
- 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 +
- Click Next.
+- 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).
- Under Add an Activity to Mobile, select Empty +
- In the Add an Activity to Mobile screen, select Empty Activity and click Next.
--- ---Activities
-An activity is one of the distinguishing features of the Android framework. Activities - provide the user with access to your app, and there may be many activities. An application - will usually have a main activity for when the user launches the application, another - activity for when she selects some content to view, for example, and other activities for - when she performs other tasks within the app. See - Activities for more information.
-- Under Customize the Activity, accept the default values +
- 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.javaapp/src/main/res/layout/activity_main.xmlapp/src/main/AndroidManifest.xmlapp/build.gradlebuild.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>/layout/menu/mipmap/values/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
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. +Android Studio installs the app on your connected device and starts it.
-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.
If you don't have a particular system image installed, + you can get it by clicking the download link.
res/layout/activity_main.xml, add the
+ java/com.example.myfirstapp/MainActivity.java,
+ 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.
DisplayMessageActivity specified
by the {@link android.content.Intent}. Now you need to create the class.
+
activity_display_message.xml
<activity>
element in AndroidManifest.xml.
@@ -199,7 +212,16 @@ protected void onCreate(Bundle savedInstanceState) {
layout.addView(textView);
}
+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: