0% found this document useful (0 votes)
7 views21 pages

COMP7506 Workshop1

The document provides a detailed guide for using Android Studio in the COMP7506 Smart Phone Apps Development course. It covers software installation, creating Android Virtual Devices, configuring modules, testing on real devices, and building a BMI calculator application. The instructions include step-by-step processes for setting up projects and coding in Java.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views21 pages

COMP7506 Workshop1

The document provides a detailed guide for using Android Studio in the COMP7506 Smart Phone Apps Development course. It covers software installation, creating Android Virtual Devices, configuring modules, testing on real devices, and building a BMI calculator application. The instructions include step-by-step processes for setting up projects and coding in Java.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

Workshop 1.

Use of
Android Studio

2024-2025
COMP7506 Smart Phone Apps Development
Dr. T.W. Chim (E-mail: twchim@cs.hku.hk)
Using your own
computer

2
Installation of Software
Google provides an ALL-IN-ONE developer tool,
Android Studio, which consists of:
Android SDK Tools
Android Platform-tools
The latest Android platform
The latest Android system image for the emulator:
https://developer.android.com/studio/index.html

3
Creating Android Virtual Device
An Android Virtual Device (AVD) is a configuration that
defines the characteristics of an Android phone, tablet,
Android Wear, or Android TV device that you want to
simulate in the Android Emulator.
The AVD Manager is an interface you can launch from
Android Studio that helps you create and manage
AVDs.
To open the AVD Manager, you can either:
Select Tools > Device Manager, or
Click Device Manager icon on the right.
Choose “Add a new device  Create Virtual Device”
4
Creating Android Virtual Device

Note: Different virtual devices have different CPU and memory requirements on your computer. 5
Installation of proper Android SDK
You may need to install SDK for different platforms (especially when you
want to open existing projects from others).

6
Configuration of Modules
Right-click “app” and choose “Open Module Settings”. There are some important items.
“Properties  Compile Sdk Version”: That version of Sdk is used for the compilation.
“Properties  Build Tools Version”: That version of build tools are used for building the APK
“Default Config  Min Sdk Version”: Your user needs that Sdk version or above to install and
run your app.
“Default Config  Target Sdk Version”: Your app is targeted at that Sdk version and if the user
is using that Sdk version, the performance will be optimal.

7
Testing on Real Devices
Android system can recognize signed APK files by default. On the
Android phone, you can click onto any signed APK file and start
the installation.
To test your app on real Android phone, you can connect your
phone with your computer via USB cable. When you run your
app, in addition of emulators, you should see your real Android
phone as a target.
Note: You may need to turn on the “Developer options” on your
Android phone before it can run your app. For example, users of
Samsung phone need to follow the steps below to turn on the
“Developer options”.
https://www.samsung.com/uk/support/mobile-devices/how-do-i-turn-on-the-developer-
options-menu-on-my-samsung-galaxy-device/

8
Starting
Android Studio

9
Starting Android Studio
Launch “Android Studio”

10
Creating a new
project

11
Start a new Android Studio project

Select “Empty Views Activity” for “Phone and Tablet”

12
Start a new Android Studio project
Type the Application name and Package name
Choose the Language “Java”
Select the Minimum SDK (e.g., API 24)

13
Building a BMI
calculator

14
Definition of BMI

𝑤𝑒𝑖𝑔ℎ𝑡 (𝑘𝑔)
𝐵𝑀𝐼 =
𝐻𝑒𝑖𝑔ℎ𝑡 𝑚 2

15
In activity_main.xml
Delete the “Hello World” TextView
Drag a LinearLayout (vertical) into the screen
Drag 2 editText (Number (Decimal)), 1 button and 1 textView into the
LinearLayout. Set their IDs as “editTextHeight”, “editTextWeight”, “button”
and “textViewResult” respectively. Change the text of the button to
“Calculate BMI”.
Drag 2 textView for showing labels. There’s no need to provide them IDs.

16
In MainActivity.java
Delete the ViewCompat block.
Declare variables for UI components
public class MainActivity extends AppCompatActivity {
private EditText height;
private EditText weight;
private TextView result;

Initialize them in OnCreate()


protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_main);
height = findViewById(R.id.editTextHeight);
weight = findViewById(R.id.editTextWeight);
result = findViewById(R.id.textViewResult);
}
17
In MainActivity.java

Implement the function for calculating BMI


public void calc(android.view.View v) {
float h = Float.parseFloat(height.getText().toString());
float w = Float.parseFloat(weight.getText().toString());
float bmi = w / h / h;
result.setText("Your BMI is: " + String.valueOf(bmi));
}

Import all missing libraries


Shortcuts for code auto-indentation:

18
In MainActivity.java

19
Assign calc() to the button
Select the button
In attribute windows,
onClick -> calc
Done! Click “Run”

20
Workshop 1.

END

2024-2025
COMP7506 Smart Phone Apps Development
Dr. T.W. Chim (E-mail: twchim@cs.hku.hk)

You might also like