Docsity
Docsity

Prepara i tuoi esami
Prepara i tuoi esami

Studia grazie alle numerose risorse presenti su Docsity


Ottieni i punti per scaricare
Ottieni i punti per scaricare

Guadagna punti aiutando altri studenti oppure acquistali con un piano Premium


Guide e consigli
Guide e consigli


Guida pratica all'uso di Android Studio per sviluppare app Android, Dispense di Elementi di Informatica

Una panoramica su come utilizzare android studio per sviluppare app android. Comprende informazioni su come creare il tuo primo progetto, la struttura del progetto, la creazione di layout e viste a scorrimento, l'uso di textview e di controlli di input, e come gestire risorse. Inoltre, vengono fornite informazioni su come utilizzare la libreria di supporto di android, menù e dialoghi, e come testare e ottimizzare l'app.

Tipologia: Dispense

2018/2019

Caricato il 20/08/2019

mariagioia-petrocchi
mariagioia-petrocchi 🇮🇹

1 documento

1 / 434

Toggle sidebar

Questa pagina non è visibile nell’anteprima

Non perderti parti importanti!

bg1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c
pf5d
pf5e
pf5f
pf60
pf61
pf62
pf63
pf64

Anteprima parziale del testo

Scarica Guida pratica all'uso di Android Studio per sviluppare app Android e più Dispense in PDF di Elementi di Informatica solo su Docsity!

Table of Contents

Introduction Unit 1. Get started Lesson 1: Build your first app 1.0: Introduction to Android 1.1: Create Your First Android App 1.2: Layouts, Views and Resources 1.3: Text and Scrolling Views 1.4: Resources to Help You Learn Lesson 2: Activities 2.1: Understanding Activities and Intents 2.2: The Activity Lifecycle and Managing State 2.3: Activities and Implicit Intents Lesson 3: Testing, debugging, and using support libraries 3.1: The Android Studio Debugger 3.2: Testing your App 3.3: The Android Support Library Unit 2. User experience Lesson 4: User interaction 4.1: User Input Controls 4.2: Menus 4.3: Screen Navigation 4.4: RecyclerView Lesson 5: Delightful user experience 5.1: Drawables, Styles, and Themes 5.2: Material Design 5.3: Providing Resources for Adaptive Layouts Lesson 6: Testing your UI 6.1: Testing the User Interface Unit 3. Working in the background Lesson 7: Background Tasks 7.1: AsyncTask and AsyncTaskLoader 7.2: Connect to the Internet 7.3: Broadcast Receivers 7.4: Services Lesson 8: Triggering, scheduling and optimizing background tasks 8.1: Notifications 8.2: Scheduling Alarms 8.3: Transferring Data Efficiently Unit 4. All about data

Table of Contents

Android Developer Fundamentals Course – Concepts

Android Developer Fundamentals is a training course created by the Google Developer Training team. You learn basic Android programming concepts and build a variety of apps, starting with Hello World and working your way up to apps that use content providers and loaders.

Android Developer Fundamentals prepares you to take the exam for the Associate Android Developer Certification.

This course is intended to be taught in a classroom, but all the materials are online, so if you like to learn by yourself, go ahead!

Prerequisites

Android Developer Fundamentals is intended for new and experienced developers who already have Java programming experience and now want to learn to build Android apps.

Course materials

The course materials include:

This concept reference, which teaches subjects you need to learn to complete the exercises in the practical workbook. Some lessons are purely conceptual and do not have an accompanying practical. The practical workbook: Android Developer Fundamentals Course—Practicals Slide decks (for optional use by instructors) Videos of lectures (for reference by instructors and students)

What topics are covered?

Android Developer Fundamentals includes five teaching units, which are described in What does the course cover?

Developed by the Google Developer Training Team

Introduction

Last updated: February 2017

This work is licensed under a Creative Commons Attribution-Non Commercial 4.0 International License

Introduction

content.

Best experience for app users

Android provides a touch-screen user interface (UI) for interacting with apps. Android's user interface is mainly based on direct manipulation, using touch gestures such as swiping, tapping and pinching to manipulate on-screen objects. In addition to the keyboard, there’s a customizable virtual keyboard for text input. Android can also support game controllers and full-size physical keyboards connected by Bluetooth or USB.

The Android home screen can contain several pages of app icons , which launch the associated apps, and widgets , which display live, auto-updating content such as the weather, the user's email inbox or a news ticker. Android can also play multimedia content such as music, animation, and video. The figure above shows app icons on the home screen (left), playing music (center), and displaying widgets (right). Along the top of the screen is a status bar, showing information about the device and its connectivity. The Android home screen may be made up of several pages, between which the user can swipe back and forth.

Android is designed to provide immediate response to user input. Besides a fluid touch interface, the vibration capabilities of an Android device can provide haptic feedback. Internal hardware such as accelerometers, gyroscopes and proximity sensors, are used by many apps to respond to additional user actions. These sensors can detect rotation of the screen from portrait to landscape for a wider view or it can allow the user to steer a virtual vehicle in a racing game by rotating the device as if it were a steering wheel.

1.0: Introduction to Android

The Android platform, based on the Linux kernel, is designed primarily for touchscreen mobile devices such as smartphones and tablets. Since Android devices are usually battery-powered, Android is designed to manage processes to keep power consumption at a minimum, providing longer battery use.

Easy to develop apps

Use the Android software development kit (SDK) to develop apps that take advantage of the Android operating system and UI. The SDK includes a comprehensive set of development tools including a debugger, software libraries of prewritten code, a device emulator, documentation, sample code, and tutorials. Use these tools to create apps that look great and take advantage of the hardware capabilities available on each device.

To develop apps using the SDK, use the Java programming language for developing the app and Extensible Markup Language (XML) files for describing data resources. By writing the code in Java and creating a single app binary, you will have an app that can run on both phone and tablet form factors. You can declare your UI in lightweight sets of XML resources, one set for parts of the UI that are common to all form factors, and other sets for features specific to phones or tablets. At runtime, Android applies the correct resource sets based on its screen size, density, locale, and so on.

To help you develop your apps efficiently, Google offers a full Java Integrated Development Environment (IDE) called Android Studio, with advanced features for developing, debugging, and packaging Android apps. Using Android Studio, you can develop on any available Android device, or create virtual devices that emulate any hardware configuration.

Android provides a rich development architecture. You don’t need to know much about the components of this architecture, but it is useful to know what is available in the system for your app to use. The following diagram shows the major components of the Android stack — the operating system and development architecture.

In the figure above:

  1. Apps: Your apps live at this level, along with core system apps for email, SMS messaging, calendars, Internet browsing, or contacts.
  2. Java API Framework: All features of Android are available to developers through application programming interfaces (APIs) written in the Java language. You don't need to know the details of all of the APIs to learn how to develop Android apps, but you can learn more about the following APIs, which are useful for creating apps: View System used to build an app's UI, including lists, buttons, and menus. Resource Manager used to access to non-code resources such as localized strings, graphics, and layout files. Notification Manager used to display custom alerts in the status bar. Activity Manager that manages the lifecycle of apps. Content Providers that enable apps to access data from other apps.

1.0: Introduction to Android

N/A 1.1 9 February 2009 2

Cupcake 1.5 27 April 2009 3

Donut

1.6 15 September 2009 4

Eclair

2.0 – 2.1 26 October 2009 5–

Froyo

2.2 – 2.2.3 20 May 2010 8

Gingerbread

1.0: Introduction to Android

2.3 – 2.3.7 6 December 2010 9–

Honeycomb

3.0 – 3.2.6 22 February 2011 11–

Ice Cream Sandwich

4.0 – 4.0.4 18 October 2011 14–

Jelly Bean

1.0: Introduction to Android

6.0 – 6.0.1 5 October 2015 23

Nougat

7.0 22 August 2016 24

See previous versions and their features at The Android Story.

The Dashboard for Platform Versions is updated regularly to show the distribution of active devices running each version of Android, based on the number of devices that visit the Google Play Store. It's a good practice to support about 90% of the active devices, while targeting your app to the latest version.

Note: To provide the best features and functionality across Android versions, use the Android Support Library in your app. This support library allows your app to use recent platform APIs on older devices.

The challenges of Android app development

While the Android platform provide rich functionality for app development, there are still a number of challenges you need to address, such as:

Building for a multi-screen world Getting performance right Keeping your code and your users secure Remaining compatible with older platform versions Understanding the market and the user.

Building for a multi-screen world

1.0: Introduction to Android

Android runs on billions of handheld devices around the world, and supports various form factors including wearable devices and televisions. Devices can come in different sizes and shapes that affect the screen designs for UI elements in

your apps.

In addition, device manufacturers may add their own UI elements, styles, and colors to differentiate their products. Each manufacturer offers different features with respect to keyboard forms, screen size, or camera buttons. An app running on one device may look a bit different on another. The challenge for many developers is to design UI elements that can work on all devices It is also the developer’s responsibility to provide an app’s resources such as icons, logos, other graphics, and text styles to maintain uniformity of appearance across different devices.

Maximizing app performance

An app's performance—how fast it runs, how easily it connects to the network, and how well it manages battery and memory usage—is affected by factors such as battery life, multimedia content, and Internet access. You must be aware of these limitations and write code in such a way that the resource utilization is balanced and distributed optimally. For example, you will have to balance the background services by enabling them only when necessary; this will save battery life of the user’s device.

Keeping your code and your users secure

You need to take precautions to secure your code and the user’s experience when using your app. Use tools such as ProGuard (provided in Android Studio), which detects and removes unused classes, fields, methods, and attributes, and encrypt all of your app's code and resources while packaging the app. To protect your user's critical information such as logins and passwords, you must secure the communication channel to protect data in transit (across the Internet) as well as data at rest (on the device).

Remaining compatible with older platform versions

Consider how to add new Android platform version features to an app, while ensuring that the app can still run on devices with older platform versions. It is impractical to focus only on the most recent Android version, as not all users may have upgraded or may be able to upgrade their devices.

Learn more

The Android Story Android API Guide, "Develop" section: Introduction to Android Platform Architecture

1.0: Introduction to Android

1.1: Create Your First Android App

Contents:

The development process Using Android Studio Exploring a project Viewing and editing Java code Viewing and editing layouts Understanding the build process Running the app on an emulator or a device Using the log Related practical Learn more

This chapter describes how to develop applications using the Android Studio Integrated Development Environment (IDE).

The development process

An Android app project begins with an idea and a definition of the requirements necessary to realize that idea. As the project progresses, it goes through design, development, and testing.

The above diagram is a high-level picture of the development process, with the following steps:

Defining the idea and its requirements: Most apps start with an idea of what it should do, bolstered by market and user research. During this stage the app's requirements are defined. Prototyping the user interface: Use drawings, mock ups and prototypes to show what the user interface would look like, and how it would work. Developing and testing the app: An app consists of one or more activities. For each activity you can use Android Studio to do the following, in no particular order: Create the layout: Place UI elements on the screen in a layout, and assign string resources and menu items, using the Extensible Markup Language (XML). Write the Java code: Create source code for components and tests, and use testing and debugging tools. Register the activity: Declare the activity in the manifest file. Define the build: Use the default build configuration or create custom builds for different versions of your app. Publishing the app : Assemble the final APK (package file) and distribute it through channels such as the Google Play.

Using Android Studio

1.1: Create Your First Android App

Android Studio provides tools for the testing, and publishing phases of the development process, and a unified development environment for creating apps for all Android devices. The development environment includes code templates with sample code for common app features, extensive testing tools and frameworks, and a flexible build system.

Starting an Android Studio project

After you have successfully installed the Android Studio IDE, double-click the Android Studio application icon to start it. Choose Start a new Android Studio project in the Welcome window, and name the project the same name that you want to use for the app.

When choosing a unique Company Domain, keep in mind that apps published to the Google Play must have a unique package name. Since domains are unique, prepending the app's name with your name, or your company's domain name, should provide an adequately unique package name. If you are not planning to publish the app, you can accept the default example domain. Be aware that changing the package name later is extra work.

Choosing target devices and the minimum SDK

When choosing Target Android Devices, Phone and Tablet are selected by default, as shown in the figure below. The choice shown in the figure for the Minimum SDK — API 15: Android 4.0.3 (IceCreamSandwich) — makes your app compatible with 97% of Android devices active on the Google Play Store.

Different devices run different versions of the Android system, such as Android 4.0.3 or Android 4.4. Each successive version often adds new APIs not available in the previous version. To indicate which set of APIs are available, each version specifies an API level. For instance, Android 1.0 is API level 1 and Android 4.0.3 is API level 15.

The Minimum SDK declares the minimum Android version for your app. Each successive version of Android provides compatibility for apps that were built using the APIs from previous versions, so your app should always be compatible with future versions of Android while using the documented Android APIs.

Choosing a template

Android Studio pre-populates your project with minimal code for an activity and a screen layout based on a template. A variety of templates are available, ranging from a virtually blank template (Add No Activity) to various types of activities.

1.1: Create Your First Android App

The Android Studio main window is made up of several logical areas, or panes , as shown in the figure below.

In the above figure:

  1. The Toolbar .The toolbar carries out a wide range of actions, including running the Android app and launching Android tools.
  2. The Navigation Bar. The navigation bar allows navigation through the project and open files for editing. It provides a more compact view of the project structure.
  3. The Editor Pane. This pane shows the contents of a selected file in the project. For example, after selecting a layout (as shown in the figure), this pane shows the layout editor with tools to edit the layout. After selecting a Java code file, this pane shows the code with tools for editing the code.
  4. The Status Bar****. The status bar displays the status of the project and Android Studio itself, as well as any warnings or messages. You can watch the build progress in the status bar.
  5. The Project Pane. The project pane shows the project files and project hierarchy.
  6. The Monitor Pane. The monitor pane offers access to the TODO list for managing tasks, the Android Monitor for monitoring app execution (shown in the figure), the logcat for viewing log messages, and the Terminal application for performing Terminal activities.

Tip : You can organize the main window to give yourself more screen space by hiding or moving panes. You can also use keyboard shortcuts to access most features. See Keyboard Shortcuts for a complete list.

Exploring a project

Each project in Android Studio contains the AndroidManifest.xml file, component source-code files, and associated resource files. By default, Android Studio organizes your project files based on the file type, and displays them within the Project: Android view in the left tool pane, as shown below. The view provides quick access to your project's key files.

1.1: Create Your First Android App

To switch back to this view from another view, click the vertical Project tab in the far left column of the Project pane, and choose Android from the pop-up menu at the top of the Project pane, as shown in the figure below.

In the figure above:

  1. The Project tab. Click to show the project view.
  2. The Android selection in the project drop-down menu.
  3. The AndroidManifest.xml file. Used for specifying information about the app for the Android runtime environment. The template you choose creates this file.
  4. The java folder. This folder includes activities, tests, and other components in Java source code. Every activity, service, and other component is defined as a Java class, usually in its own file. The name of the first activity (screen) the user sees, which also initializes app-wide resources, is customarily MainActivity.
  5. The res folder. This folder holds resources, such as XML layouts, UI strings, and images. An activity usually is associated with an XML resource file that specifies the layout of its views. This file is usually named after its activity or function.
  6. The build.gradle (Module: App) file. This file specifies the module's build configuration. The template you choose creates this file, which defines the build configuration, including the minSdkVersion attribute that declares the minimum version for the app, and the targetSdkVersion attribute that declares the highest (newest) version for which the app has been optimized. This file also includes a list of dependencies , which are libraries required by the code — such as the AppCompat library for supporting a wide range of Android versions. 1

Viewing the Android Manifest

Before the Android system can start an app component, the system must know that the component exists by reading the app's AndroidManifest.xml file. The app must declare all its components in this file, which must be at the root of the app project directory.

1.1: Create Your First Android App