37
Creating the First App with Android Studio BY- Parinita Agarwal B.Tech C.S 3 rd year Radha Govind Engineering College

Creating the first app with android studio

Embed Size (px)

Citation preview

Creating the First App with Android StudioBY-Parinita Agarwal B.Tech C.S 3rd yearRadha Govind Engineering College

1

ContentsIntroduction of AndroidWhat is Android Studio?Starting up with Android Studio.Creating an application.

What is Android ?In English dicitionary the world android means that-An automation that resambles a human being,Mechanical man or humanoid ..etc.Android is an open source operating system specifically for use on mobile devices ( smart phones and tablets).Based on the Linux kernel(2.6 kernel).Developed by Google and later by the Open Handset Alliance(OHA).Allows writing managed code in the Java language.

3

Android has its own virtual machine i.e , DVM (Dalvik Virtual Machine), which is used for executing the android applications.Supports Bluetooth, Wi-Fi, and 3G and 4G networking.

Android StudioAndroid Studio is a new Android development environment developed by Google. It is based on IntellJ IDEA, which is similar to Eclipse with the ADT (Android Development Toolkit) plugin .It is different from Eclipse in many ways. The most basic difference is that we dont have to do any configuration like we would have do to for Eclipse. Android Studio comes bundled with the Android ADT, and all we need to do is to point it to where Java is installed on ours/s .

JDK version must be later than version 6.Once downloaded, you can follow the set-up wizard. At times, for Windows systems, the launcher script isnt able to find Java. So we need to set an environment variable called JAVA_HOME and point it to our JDK folder.Now that the set-up is complete, we can go ahead and directly launch the Android Studio. There is no need to download the ADT plugin and configure it. When we launch it, we can see the Welcome screen (refer to Figure 2).

Some specific features that come with Android Studio (and quoting directly from the Android Developers Web page):Gradle-based build support.Android-specific refactoring and quick fixes Lint tools to improve performance, usability, version compatibility .ProGuard and app-signing capabilities.A rich layout editor that allows you to drag-and-drop UI components, preview layouts on multiple screen configurations, and much more.

Fig 1Starting up with Android Studio

8

Creating a New ProjectThe first step in the application development process is to create a new project within the Android Studio environment. Begin, therefore, by launching Android Studio so that the Welcome to Android Studio screen appears as illustrated in Figure 2:

Fig 2

Once this window appears, Android Studio is ready for a new project to be created. To create the new project, simply click on the Start a new Android Studio project option to display the first screen of the New Project wizard as shown in Figure 3:

Defining the ProjectIn the New Project window, set the Application name field to AndroidSample(Fig 3). The application name is the name by which the application will be referenced and identified within Android Studio.The Package Name is used to uniquely identify the application within the Android application ecosystem. It should be based on the reversed URL of your domain name followed by the name of the application. For example, if our domain is www.mycompany.com, and the application has been named AndroidSample , then the package name might be specified as follows: com.example.parinita.androidsample

The Project location setting will define our project will be get store(Fig 3).Click Next to proceed.

Fig 3

Selecting the form factorsOn the form factors screen, enable the Phone and Tablet option and set the minimum SDK setting to API 8: Android 4.0.3 (IceCremeSandwich). The reason for selecting an older SDK release is that this ensures that the finished application will be able to run on the widest possible range of Android devices. Since the project is not intended for Google TV, Google Glass or wearable devices, leave the remaining options disabled before clicking Next.

Fig 4

16

Selecting an ActivityThe next step is to define the type of initial activity that is to be created for the application. A range of different activity types is available when developing Android applications. Here we select the option to create a Blank Activity.

Fig 5

With the Blank Activity option selected, click Next.On the final screen (Figure 6) name the:Activity Name: Name of the activity to load. Layout Name : Every screen (activity) UI is designed using an XML File. This layout will define the layout of the activity.Title : It is the title of the activity. Menu Resource Name : This file will decide what should be displayed when the user clicks on the Menu of the android app screen.

Fig 6

Finally, click on Finish. The project gets created and will be shown as below.

Fig 7

22

Important files and directory of Android project to be known and their purpose :

src - This contains the .java source files for our project. By default, it includes an AndroidSampleActivity.java source file having an activity class that runs when your app is launched using the app icon.generated - This contains the .R file, a compiler-generated file that references all the resources found in your project.bin - This folder contains the Android package files .apk built by the ADT during the build process and everything else needed to run an Android application.

res/layout - This is a directory for files that define your app's user interface.res/values - This is a directory for other various XML files that contain a collection of resources, such as strings and colors definitions.AndroidManifest.xml - This is the manifest file which describes the fundamental characteristics of the app and defines each of its components.

Layout FileThe activity_android_sample.xml is a layout file available in res/layout directory, that is referenced by our application when building its interface.String fileThe strings.xml file is located in the res/values folder and it contains all the text that our application uses. For example, the names of buttons, labels, default text, and similar types of strings go into this file. This file is responsible for their textual content. The gen/com.example.parinita.androidsample/R.java file is the glue between the activity Java files like AndroidSampleActivity.java and the resources like strings.xml. It is an automatically generated file and we should not modify the content of the R.java file.

Text Mode

Layout Design

Running the app on EmulatorThe Android SDK includes a mobile device emulator a virtual mobile device that runs on our computer. The emulator lets us develop and test Android applications without using a physical device.Emulator can be started from SDK manager tools.The Android SDK separates tools, platforms, and other components into packages such as debugger, libraries, an emulator, documentation, sample code.

AVD ManagerAn Android Virtual Device or AVD is an emulator configuration, allowing you to model an Android device. This makes running and testing applications on a wide range of devices much easier. With an Android Virtual Device, we can specifythe hardware and software theAndroid Emulatorneeds to emulate.The preferred way to create an Android Virtual Device is through theAVD Manager, which can be access in Android Studio by selectingAndroid > AVD Managerfrom theToolsmenu.

To use newly created AVD, select it from the list in the AVD manager, and clickStart. If AVD is set up correctly, the Android Emulator should launch as shown in the screenshot below.

With the Android Emulator up and running, it's time to launch the application byselectingRun from theRunmenu. And our application runs on the Android Emulator.

THANK YOU