1.4: Learning About Available Resources

Contents:

In this practical you will:

  • Explore some of the many resources available to Android developers of all levels.
  • Add a home screen icon to your Word List app; tapping the icon will launch the app.

What you should already KNOW

From previous practicals, you should be able to:

  • Understand the basic work flow of Android Studio.

What you will LEARN

Where to find developer resources:

What you will DO

In this practical you will:

  • Explore and use Android developer resources.
  • Use developer resources to figure out how to add an icon to the home screen of your device.
    When this icon is clicked, your app launches.

App Overview

You will use the existing HelloToast app and add a launcher icon to it.

Task 1. Explore the official Android developer documentation

You can find the official Android developer documentation at:

http://developer.android.com/index.html

This documentation contains a wealth of information that is kept current by Google.

1.1. Explore the official Android documentation

  1. Go to http://developer.android.com/index.html.
  2. At the top of the page, look for the Design, Develop, and Distribute links. Follow each of the links and familiarize yourself with the navigation structure.
    • Design is all about Material Design, which is a conceptual design philosophy that outlines how apps should look and work on mobile devices. Scroll to the bottom of the landing page for links to resources such as sticker sheets and color palettes.
    • Develop is where you can find API information, reference documentation, tutorials, tool guides, and code samples. You can use the site navigation or search to find what you need.
    • Distribute is about everything that happens after you've written your app: putting it on the Play Store, growing your user base, and earning money.
  3. Use search or navigate the documentation to complete the following tasks:
    • Add a launcher icon to the Word List app. See the API Guide to Launcher Icons to learn more about how to design effective launcher icons.
    • Learn how to monitor your app's resource usage in Android Studio.

Task 2. Use project templates

Android Studio provides templates for common and recommended app and activity designs. Using built-in templates saves time, and helps you follow design best practices.

Each template incorporates an skeleton activity and user interface. You've already used the Empty Activity template. The Basic Activity template has more features and incorporates recommended app features, such as the options menu.

2.1. Explore the Basic Activity architecture

The Basic Activity template is a versatile template provided by Android Studio to assist you in jump-starting your app development.

  1. In Android Studio, create a new project with the Basic Activity template.
  2. Build and run the app.
  3. Identify the labelled parts on the screenshot and table below. Find their equivalents on your device or emulator screen. Annotated Basic Activity template Architecture of the Basic Activity template

    # UI Description Code reference
    1 Status bar

    This bar is provided and controlled by the Android system.

    Not visible in the template code.

    It's possible to access it from your activity. For example, you can hide the status bar, if necessary.

    2 AppBarLayout > Toolbar

    App bar (also called Action bar) provides visual structure, standardized visual elements, and navigation. For backwards compatibility, the AppBarLayout in the template embeds a Toolbar widget with the same functionality.

    ActionBar class

    Challenge: App Bar Tutorial

    activity_main.xml

    Look for android.support.v7.widget.Toolbar

    inside android.support.design.widget.AppBarLayout.

    Change the toolbar to change the appearance of its parent, the app bar.

    3 Application name

    This is derived from your package name, but can be anything you choose.

    AndroidManifest.xml

    android:label="@string/app_name"

    4 Options menu overflow button

    Menu items for the activity, as well as global options, such as "Search" and "Settings" for the settings menu. Your app menu items go into this menu.

    MainActivity.java

    onOptionsItemSelected() implements what happens when a menu item is selected.

    res > menu > menu_main.xml

    Resource that specifies the menu items for the options menu.

    5 CoordinatorLayout

    CoordinatorLayout is a feature-rich layout that provides mechanisms for views to interact. Your app's user interface goes inside this view group.

    activity_main.xml

    Notice that there are no views specified in this layout; rather, it includes another layout with

    <include layout="@layout/content_main" />

    where the views are specified. This separates system views from the views unique to your app.

    6 TextView

    In the example, used to display "Hello World". Replace this with the views for your app.

    content_main.xml

    All your app's views are defined in this file.

    7 Floating Action button (FAB) activity_main.xml

    MainActivity.java > onCreate has a stub that sets an onClick listener on the FAB.

  4. Also inspect the corresponding Java code and XML configuration files.

    Being familiar with the Java source code and XML files will help you extend and customize this template for your own needs.

    See Accessing Resources for details on the XML syntax for accessing resources.

  5. After you understand the template code, try the following:
    • Change the color of the app bar (toolbar).
    • Look at the styles associated with the app bar (toolbar).
    • Change the name of your app that's displayed in the app bar (toolbar).

2.2. Explore how to add an activity using templates

For the practicals so far, you've used the Empty Activity and Basic Activity templates. In later lessons, the templates use will vary, depending on the task.

These activity templates are also available from inside your project, so that you can add more activities to your app after the initial project setup. (You will learn more about this this in a later chapter.)

  1. Create a new project or choose an existing project.
  2. In your project directory, in the Android view, right-click the folder with your java files.
  3. Choose New > Activity > Gallery.
  4. Add one of those activities, for example, the Navigation Drawer Activity. Find the layout files for the Navigation Drawer Activity and display them in Design.

Task 3. Learn from example code

Android Studio, as well as the Android documentation provide many code samples that you can study, copy, and incorporate with your projects.

3.1. Android code samples

You can explore hundreds of code samples directly from Android Studio.

  1. In Android Studio, choose File > New > Import Sample.
  2. Browse the samples.
  3. Look at the Description and Preview tabs to learn more about each sample.
  4. Choose a sample and click Next.
  5. Accept the defaults and click Finish.
Note: The samples contained here are meant as a starting point for further development. We encourage you to design and build your own ideas into them.

3.2. Use the SDK Manager to install offline documentation

Installing Android Studio also installs essentials of the Android SDK (Software Development Kit). However, additional libraries and documentation are available, and you can install them using the SDK Manager.

  1. Choose Tools > Android > SDK Manager. This opens the Default Preferences settings.
  2. In the left-hand navigation, find and open the settings for Android SDK.
  3. Click SDK Platforms in the settings window. You can install additional versions of the Android system from here.
  4. Click on SDK Update Sites. Android Studio checks the listed and checked sites regularly for updates.
  5. Click on the SDK Tools tab. Here you can install additional SDK Tools that are not installed by default, as well as an offline version of the Android developer documentation. This gives you access to documentation even when you are not connected to the internet.
  6. Check "Documentation for Android SDK", click Apply, and follow the prompts.
  7. Navigate to the Android/sdk directory and open the docs folder.
  8. Find index.html and open it.

Task 4. Many more resources

  • The Android Developer YouTube channel is a great source of tutorials and tips.
  • The Android team posts news and and tips on the Official Android Blog.
  • Stack Overflow is a community of millions of programmers helping each other. If you run into a problem, chances are, someone else has already posted an answer on this forum. On Stack Overflow , you can even ask, "How do I setup and use ADB over WiFi?", or "What are the most common memory leaks in Android development?"
  • And last but not least, type your questions into Google search, and the Google search engine will collect relevant results from all of these resources. For example, "What is the most popular Android OS version in India?"

4.1. Search on Stack Overflow using tags

  1. Go to Stack Overflow
  2. In the search box, type [android].

    The [] brackets indicate that you want to search for posts that have been tagged as being about Android.

  3. You can combine tags and search terms to make your search more specific. Search for
    • [android] and [layout]
    • [android] "hello world"
  4. Read more about the many ways in which you can search on Stackoverflow.

Summary

  • Official Android Developer Documentation - http://developer.android.com
  • Material Design is a conceptual design philosophy that outlines how apps should look and work on mobile devices.
  • The Google Play store is Google's digital distribution system for apps developed with the Android SDK.
  • Android Studio provides templates for common and recommended app and activity designs. These templates offer working code for common use cases.
  • When you create a project, you can choose a template for your first activity.
  • While you are further developing your app, activities and other app components can be created from built-in templates.
  • Android Studio contains many code samples that you can study, copy, and incorporate with your projects.

The related concept documentation is in Android Developer Fundamentals: Concepts.

Learn more

Developer Documentation:

Code

Videos

results matching ""

    No results matching ""