Basic Android Tutorial USF’s Association for Computing Machinery

Preview:

Citation preview

Basic Android Tutorial

USF’s Association for Computing Machinery

Overview of Tutorial

1. What You Need2. Create the Project3. Overview of Files4. Create the Layout5. Create the Functionality6. Debugging7. Publish App8. Download to Device

What You Need

• Android Studio and Android SDK• Android device and charging cable (Optional)– The emulator can be used, but it is very slow

• OEM USD Drive (For Windows users only)– Only necessary if you are not using the emulator– Follow these instructions

• Resume Information (Optional)– You can just use gibberish until you have a resume

• This image file: USFLogo.png

Create The ProjectNew Project

Create The ProjectName and Domain

• App Name:– “[Yourname]Resume”

• Domain– Normally the

developer’s website– If you don’t have a

website default to: [netid].myweb.usf.edu

Create The ProjectSelect SDK

• Only use Phone and Tablet for now

• The Min SDK affects what features and libraries are available to your app.

Create The ProjectSelect First Activity

Create The ProjectName First Activity

Overview of FilesLayout Files

• Language: XML• Determines the

User Interface

Overview of FilesBackend Files

• Language: Java• Determines the

App’s Behavior

Overview of FilesImage Resource Files

• Contain the images that will be used in your app

• Currently contains nothing, we’ll add an image later

Overview of FilesStrings and Styles

• Strings.xml– Contains the text

associated with each string ID

• Styles.xml– Contains info for

custom themes

Overview of FilesApp Manifest

• Presents essential information to the Android system– Java package name– Activities and Services– Permissions– Min Level of API– Referenced Libraries

Overview of FilesGradle Build File

• Automates many of the build processes for Android Studio

• Contains build info– SDK Version– Dependencies– Build type

Add the ResourcesAdd an Image

1. Download the Image2. Copy/Paste into the drawable folder of your

app– C:\Users\USERNAME\AndroidStudioProjects\

APPNAME\app\src\main\res\drawable

3. Finish

Add the ResourcesAdd Strings

1. Open strings.xml2. Add strings for the

following categories– Contact Info– Education Info– Work Experience– Extracurricular

Activities

• Download Example Here

Add the ResourcesAdd Styles

1. Open styles.xml2. Add styles for the

following categories– Your Name– Section Title– Item Header– Content– Content Holder

• Download Example Here

Create the UILayout Format

1. In Text Editor change “RelativeLayout” to “LinearLayout”

2. Specify orientation– android:orientation="vertical“

3. Remove existing Textview

• Types of Layout– Relative: specify the location

of child objects relative to each other

– Linear: organizes its children into a single horizontal or vertical row

Create the UIAdd Name and Headers

1. Create TextView for your name, with the style “name”

2. Add TextViews for the following categories, with the style “sectionTitle”– Contact Info– Education Info– Work Experience– Extracurricular Activities

1

2

Create the UILayout So Far

Create the UINested Layout and Content

1. Create a vertical Linear Layout underneath “contactTitle”– Use the style “contentHolder”

2. Add TextViews for each of the following, with the style “content”– Address– Email– Phone Number

3. Do this for all the content headers

Create the UILayout So Far

Create the UIAdd an Image

1. Add an ImageView above name

2. Set the source to the drawable image resource we added earlier

Create the UINested Layout and Content

1. Create a vertical Linear Layout underneath “contactTitle”– Use the style “contentHolder”

2. Add TextViews for each of the following, with the style “content”– Address– Email– Phone Number

3. Do this for all the content headers

Create the UIAdd A Button

1. Add a button at the end of the layout.

2. Set the top margin to 50px

3. Set the id to “linkedin”– Or anything really

• Download Layout Example Here

Test it OutSetup your System to Debug

(if using the emulator, skip this)

1. Verify that your application is "debuggable" in your manifest or build.gradle file. – Remember to undo this before

publishing

2. Enable debugging on your device

i. (If Android 3.2 or lower): Settings > Applications > Development

ii. Settings > About phoneiii. Tap Build number seven times. iv. Return to the previous screen

to find Developer options

AndroidManifext.xml

build.gradle (Module: app)

Test it OutSet up your system to detect your device

(if using the emulator, skip this)

• Windows: Follow the instructions here• Mac OS X: It just works. Skip this step.• Ubuntu Linux: You’re over complicating this.

Test it OutConnect Device and Debug

1. Connect device with USB cable– If using emulator: load

it up

2. Run or Debug3. Select your device or

emulator and click OK

Run Debug

Create the UIOh no! It doesn’t scroll!

• Layouts do not scroll on their own. They need a control that contains a scrolling action.

1. Replace the LinearLayout root element with a ScrollView– Be sure to delete the

orientation tag

2. Add a LinearLayout within the ScrollView

3. Change/Add the end tags

.

.

.

Create the FunctionalityButton Click Event

1. Open Resume.java2. Reference Button from the

layout3. Set click listener and handler4. There will be several errors.

To fix, include the following references:– android.widget.Button– android.content.Intent– android.net.Uri

• Download Example Here

4

2

3

Debugging

1. Set a debug point– Click on the vertical bar to

the left of the code– Or, hit Ctrl+F8 with the

line selected

2. Click Debug– Step Over/Next Line: F8– Step Into: F7– Step Out/Return: Shift+F8

Publish App

1. Turn off debugging– ApplicationManifest.xml– build.gradle

2. Sign your Applicationi. Build > Generate Signed

APKii. Create New…iii. Fill in all fieldsiv. Okv. Nextvi. Finish

Publish AppEmail APK file to your device

1. C:\Users\USERNAME\AndroidStudioProjects\APPNAME\app

2. There will be a file ending in .apk3. Email APK file to yourself4. Open email on your android device and

download APK file5. It will ask you to install6. Now you can send your resume app to

everyone you know!

THE END

Recommended