INTRODUCTION TO ANDROID AND JAVA
Prepared by: Dr. Gandhimathi
Android API
Setting up Android Studio
Step 1: Head over to https://developer.android.com/studio/#downloads to get the Android Studio
executable or zip file.
Step 2: Click on the Download Android Studio Button.
Step 3: After the downloading has finished, open the file from downloads and run it. It will prompt the
dialog box. Click on next. In the next prompt, it’ll ask for a path for installation. Choose a path and hit next.
Step 4: It will start the installation, and once it is completed, Click on next.
Step 5: Once “Finish” is clicked, it will ask whether the previous settings need to be imported [if the android
studio had been installed earlier], or not. It is better to choose the ‘Don’t import Settings option’. Click
the OK button.
Step 6: This will start the Android Studio. Meanwhile, it will be finding the available SDK components.
Step 7: After it has found the SDK components, it will redirect to the Welcome dialog box. Click on next
Choose Standard and click on Next. Now choose the theme, whether the Light theme or the Dark one. The
light one is called the IntelliJ theme whereas the dark theme is called Dracula. Choose as required. Click on
the Next button.
Step 8: Now it is time to download the SDK components. Click on Finish. Components begin to download let
it complete. The Android Studio has been successfully configured. Now it’s time to launch and build
apps. Click on the Finish button to launch it.
Step 9: Click on Start a new Android Studio project to build a new app.
Structure of Android Java Code
Basic Android project structure
Every Android project contains several folders:
•src: This folder contains the Java source files.
•gen: Generated Java library, this library is for Android internal use only.
•Res: Here we can store resource files such as pictures, XML files for defining layouts, and so forth. Within this
folder there are additional folders such as Drawable, Layout, and Values.
•Drawable: Here we store the various graphic files. We can see three types of drawable folders. This is because
there are many Android devices with different screen resolutions. By default, there are several versions of this
folder such as: Drawable-mdpi, drawable-hdpi, and so forth. This is required in order to adapt to different screen
resolutions.
•Layout: This is the place for XML layout files. Layout files are XML files which define how various Android
objects (such as textboxes, buttons, etc.) are organized on the screen.
•Values: XML files which store various string values (titles, labels, etc.).
Major files in the Android project:
AndroidManifest.xml: This is the Android definition file. It contains information about the
Android application such as minimum Android version, permission to access Android device
capabilities such as internet access permission, ability to use phone permission, etc.
MainLayout.xml: This file describes the layout of the page. This means the placement of
every component (such as textboxes, labels, radio buttons, user defined components, etc.) on
the app screen.
Activity class: Every application that occupies the entire device screen needs at least one
class which inherits from the Activity class. One major method is called OnCreate. This
method initiates the app and loads the layout page.
Some important definitions in this file:
• Android:versionCode: This is a numerical value. This is an important attribute because that is
how the Android device knows when to alert the user to upgrade the application to a newer
version.
• Android:sdkMinVersion: Defines what is the earliest version of the Android operating system
available to this application.
• Activity element: Defines what the activities available in this application are and which activity
has to be loaded at startup.
The Android manifest file: A typical Android.Manifest file looks like this:
Layout file
A typical layout file looks like this:
This layout defines one object, a TextView. This is a text label and it is used when a programmer wants to
place a text title in your application.
• One major class is the Activity class. We already defined this class in the android.manifest file as the main
activity class. Which is the first class to be loaded and executed right after the Android application will be
launched:
Activity class
We can see here one major method called "onCreate" which is called when the Activity class is activated.
In our specific example, we define a layout file by the line setContentView(R.layout.main).
• You can create an Android app with the Empty Activity project template provided by
Android Studio.
• To create a project in Android Studio:
1. Double click the Android Studio icon to launch Android Studio.
2. In the Welcome to Android Studio dialog, click New Project. The New Project window
opens with a list of templates provided by Android Studio.
In Android Studio, a project template is an Android project that provides the blueprint for a
certain type of app. Templates create the structure of the project and the files needed for
Android Studio to build your project. The template that you choose provides starter code to
get you going faster.
3. Make sure the Phone and Tablet tab is selected.
4. Click the Empty Activity template to select it as the template for your project. The Empty
Activity template is the template to create a simple project that you can use to build a
Compose app. It has a single screen and displays the text "Hello Android!".
5. Click Next. The New Project dialog opens. This has some fields to configure your project.
Building and Developing the Android Application
6. Configure your project as follows:
• The Name field is used to enter the name of your project, for this codelab type
"Greeting Card".
• Leave the Package name field as is. This is how your files will be organized in the file
structure. In this case, the package name will be com.example.greetingcard.
• Leave the Save location field as is. It contains the location where all the files related to
your project are saved. Take a note of where that is on your computer so that you can
find your files.
• Select API 24: Android 7.0 (Nougat) from the menu in the Minimum SDK field.
Minimum SDK indicates the minimum version of Android that your app can run on.
7. Click Finish. This may take a while.
8. You may see a What's New pane which contains updates on new features in Android
Studio. Close it for now.
9. Click Split on the top right of Android Studio, this allows you to view both code and
design. You can also click Code to view code only or click Design to view design only.
10. Click Build & Refresh. It may take a while to build but when it is done the preview
shows a text box that says "Hello Android!". Empty Compose activity contains all the
code necessary to create this app.
THANK YOU

Introduction to Android and Java.pptx

  • 1.
    INTRODUCTION TO ANDROIDAND JAVA Prepared by: Dr. Gandhimathi
  • 2.
  • 14.
    Setting up AndroidStudio Step 1: Head over to https://developer.android.com/studio/#downloads to get the Android Studio executable or zip file. Step 2: Click on the Download Android Studio Button. Step 3: After the downloading has finished, open the file from downloads and run it. It will prompt the dialog box. Click on next. In the next prompt, it’ll ask for a path for installation. Choose a path and hit next. Step 4: It will start the installation, and once it is completed, Click on next. Step 5: Once “Finish” is clicked, it will ask whether the previous settings need to be imported [if the android studio had been installed earlier], or not. It is better to choose the ‘Don’t import Settings option’. Click the OK button. Step 6: This will start the Android Studio. Meanwhile, it will be finding the available SDK components. Step 7: After it has found the SDK components, it will redirect to the Welcome dialog box. Click on next Choose Standard and click on Next. Now choose the theme, whether the Light theme or the Dark one. The light one is called the IntelliJ theme whereas the dark theme is called Dracula. Choose as required. Click on the Next button. Step 8: Now it is time to download the SDK components. Click on Finish. Components begin to download let it complete. The Android Studio has been successfully configured. Now it’s time to launch and build apps. Click on the Finish button to launch it. Step 9: Click on Start a new Android Studio project to build a new app.
  • 15.
    Structure of AndroidJava Code Basic Android project structure Every Android project contains several folders: •src: This folder contains the Java source files. •gen: Generated Java library, this library is for Android internal use only. •Res: Here we can store resource files such as pictures, XML files for defining layouts, and so forth. Within this folder there are additional folders such as Drawable, Layout, and Values. •Drawable: Here we store the various graphic files. We can see three types of drawable folders. This is because there are many Android devices with different screen resolutions. By default, there are several versions of this folder such as: Drawable-mdpi, drawable-hdpi, and so forth. This is required in order to adapt to different screen resolutions. •Layout: This is the place for XML layout files. Layout files are XML files which define how various Android objects (such as textboxes, buttons, etc.) are organized on the screen. •Values: XML files which store various string values (titles, labels, etc.).
  • 16.
    Major files inthe Android project: AndroidManifest.xml: This is the Android definition file. It contains information about the Android application such as minimum Android version, permission to access Android device capabilities such as internet access permission, ability to use phone permission, etc. MainLayout.xml: This file describes the layout of the page. This means the placement of every component (such as textboxes, labels, radio buttons, user defined components, etc.) on the app screen. Activity class: Every application that occupies the entire device screen needs at least one class which inherits from the Activity class. One major method is called OnCreate. This method initiates the app and loads the layout page.
  • 17.
    Some important definitionsin this file: • Android:versionCode: This is a numerical value. This is an important attribute because that is how the Android device knows when to alert the user to upgrade the application to a newer version. • Android:sdkMinVersion: Defines what is the earliest version of the Android operating system available to this application. • Activity element: Defines what the activities available in this application are and which activity has to be loaded at startup. The Android manifest file: A typical Android.Manifest file looks like this:
  • 18.
    Layout file A typicallayout file looks like this: This layout defines one object, a TextView. This is a text label and it is used when a programmer wants to place a text title in your application.
  • 19.
    • One majorclass is the Activity class. We already defined this class in the android.manifest file as the main activity class. Which is the first class to be loaded and executed right after the Android application will be launched: Activity class We can see here one major method called "onCreate" which is called when the Activity class is activated. In our specific example, we define a layout file by the line setContentView(R.layout.main).
  • 20.
    • You cancreate an Android app with the Empty Activity project template provided by Android Studio. • To create a project in Android Studio: 1. Double click the Android Studio icon to launch Android Studio. 2. In the Welcome to Android Studio dialog, click New Project. The New Project window opens with a list of templates provided by Android Studio. In Android Studio, a project template is an Android project that provides the blueprint for a certain type of app. Templates create the structure of the project and the files needed for Android Studio to build your project. The template that you choose provides starter code to get you going faster. 3. Make sure the Phone and Tablet tab is selected. 4. Click the Empty Activity template to select it as the template for your project. The Empty Activity template is the template to create a simple project that you can use to build a Compose app. It has a single screen and displays the text "Hello Android!". 5. Click Next. The New Project dialog opens. This has some fields to configure your project. Building and Developing the Android Application
  • 21.
    6. Configure yourproject as follows: • The Name field is used to enter the name of your project, for this codelab type "Greeting Card". • Leave the Package name field as is. This is how your files will be organized in the file structure. In this case, the package name will be com.example.greetingcard. • Leave the Save location field as is. It contains the location where all the files related to your project are saved. Take a note of where that is on your computer so that you can find your files. • Select API 24: Android 7.0 (Nougat) from the menu in the Minimum SDK field. Minimum SDK indicates the minimum version of Android that your app can run on. 7. Click Finish. This may take a while. 8. You may see a What's New pane which contains updates on new features in Android Studio. Close it for now. 9. Click Split on the top right of Android Studio, this allows you to view both code and design. You can also click Code to view code only or click Design to view design only. 10. Click Build & Refresh. It may take a while to build but when it is done the preview shows a text box that says "Hello Android!". Empty Compose activity contains all the code necessary to create this app.
  • 23.