SDMD-exercises 01 - This is the first excercise to get kickstarted with Mobile Dev in Java. More PDF

Title SDMD-exercises 01 - This is the first excercise to get kickstarted with Mobile Dev in Java. More
Course Software Development for Mobile Devices
Institution Swinburne University of Technology
Pages 3
File Size 99.6 KB
File Type PDF
Total Downloads 27
Total Views 125

Summary

This is the first excercise to get kickstarted with Mobile Dev in Java. More to come...


Description

COS30017 and COS80019

LAB 1 GET THE PARTY STARTED AIM The aim of these exercises is to get you ready for programming in this unit. We will use Android Studio for this unit, and completing these exercises will mean that you have this installed and can find your way around the IDE.

PREREQUISITES These exercises assume that you have access to Android Studio and have a system image installed. Instructions for these can be found in Module 0 in Canvas.

TASKS 1. Hello World For this task, you will create a simple Hello World app. §

Open the Android Studio IDE and select Start a new Android Studio Project. Follow the prompts (task 2 will involve looking at the screens in more detail) and you will be presented with developers standard view of Android Studio IDE. See https://developer.android.com/training/basics/firstapp/creating-project for starting a project.

§

Before running your app, you need to create an AVD (Android Virtual Device) to use it in the emulator. Start the AVD Manager (look for the icon in the top right that looks like a purple square with the Android bot in front of it) and create an Android 4.4 device by selecting the Nexus S (4.0”, 480 x 800: hdpi) from the device drop down menu. Set the

COS30017 and COS80019 target to Android 4.4 - API Level 19. Give the AVD a meaningful name. (More details are at https://developer.android.com/training/basics/firstapp/running-app and https://developer.android.com/studio/run/managing-avds.) §

Press the run button (green play button) to start your app in the emulator. If this is the first time that you are starting the emulator, it will take some time to start up.

§

If you have your own Android device — follow the instructions at https://developer.android.com/training/basics/firstapp/running-app for getting devices set up.

2. iCreate: use Android Studio to create an app Using Android Studio, create an app based on one of the templates provided. Compile and run. See https://developer.android.com/studio/projects/create-project for advice on stepping through the screens. Try File -> New Project… to start a new project. Select Empty or Basic Activity; an empty activity is the easiest to work with, but you can try any. Give your app a name and put the project in your lab directory. Select Java instead of Kotlin for the language. Set your minimum SDK to API 19 or an API of your choice (matching your device if you have one is a good choice). Continue to finish. 3. Wonderful images and text Amend the app you made in Task 2 to show some text and place an image. Hint: Images are kept in the res -> drawable folders. 4. iDebug: Create a log message Developers tend to use simple messages to get insight of a program (i.e. they put in snippets of code like System.out.println(“here”); all over the place). In Android, you have to use the Log class for this. The format for a simple debug message is: Log.d(“TAG”, “I am here”);

COS30017 and COS80019 The TAG above can be any string — so you put in the Class name, Package name or the relevant feature name that helps you group it. There are other methods too in the Log class. More information can be found at https://developer.android.com/sdk/installing/studiodebug.html and https://developer.android.com/studio/debug/am-logcat. Run your program in the Debug mode (and see the various log messages first. After this, create your own log message and see it in Logcat viewer. 5. Getting started with Java and Kotlin (extension) There are two languages used to write code in Android Studio: Java and Kotlin. If you know Java, then using Java might be the easiest approach. Android Studio is able to convert Java to Kotlin reasonably well. Alternatively if you are familiar with Swift you might find it easier to start with Kotlin from the beginning. Note code in both languages can exist side by side. Create a new project, this time ensuring that Kotlin support has been included. In the ActivityMain.kt file, write a function that takes two integers and returns their sum. Use Log messages to print out the result (simply call the function from onCreate()). Use the File menu to create a new Java class, and name it Numbers.java. In this class, write a public static Java function which takes two integers and returns their sum. In your Kotlin file, call this function. This simple example shows that Java and Kotlin can indeed live side by side. For further experimentation, try setting default parameters in the Kotlin function. Note down how you found out how to write these two functions/classes.

NEXT STEPS The assessment tasks for module 1 can now be attempted and submitted via Doubtfire....


Similar Free PDFs