0% found this document useful (0 votes)
9 views

Topic2 Slide Notes

T2
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Topic2 Slide Notes

T2
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 32

CIT 4404 Mobile App Development

Topic2: Android Application


Development Using Android Studio

Dr. Fullgence Mwakondo


Institute of Computing and Informatics
Technical University of Mombasa
[email protected]

3/13/2023 CIS 470: Mobile App Development 1


Android Application Development
Using Android Studio
 a. Exploring the IDE
 b. Using Development tools
 c. Coding Application
 d. Debugging Application
 e. Publishing application

CIT 4404: Mobile App Development


Exploring the IDE
 Open the IDE
 Start a new project
 Select options
 Project view

3/13/2023 CIS 470 Mobile App Development 3


Give the project name: IDEExplorer; use whatever domain name you like

3/13/2023 CIS 470 Mobile App Development 4


3/13/2023 CIS 470 Mobile App Development 5
The default option is Empty Activity. This is the most useful for our examples because it
creates a basic activity for you, with no code in it

3/13/2023 CIS 470 Mobile App Development 6


It is accepted practice in Android development to name your main activity—that is, the
Activity that is loaded on startup by your application—as MainActivity

The startup layout, that is the layout for the screen elements that will be displayed when
your application is started by the user, is the activity_main layout. All other layouts should
be named according to the activity that they support (activity_input, activity_delete)

Click the Finish button to finish creating the project and jump into exploring the IDE

3/13/2023 CIS 470 Mobile App Development 7


The Android Studio IDE

3/13/2023 CIS 470 Mobile App Development 8


The left side of the IDE shows the Project window.
The Project window enables you to quickly navigate
the files within your project.

3/13/2023 CIS 470 Mobile App Development 9


On the right side of the IDE are the Editor tabs. The Editor tabs are
where you write and work with your code files.

3/13/2023 CIS 470 Mobile App Development 10


• To work on a new file, simply locate the file in the Project
window and double-click it to open a new Editor tab that contains
that file’s code.
• If you need to create a new file from scratch, right-click the
directory into which you want to place your file, and select New
➪ <File Type> from the context menu.
• At the bottom of the IDE, you should see a button labeled
LogCat. Logcat displays most of the helpful messages that are
output by your application while you are trying to debug it.

3/13/2023 CIS 470 Mobile App Development 11


Project structure of Android App

3/13/2023 CIS 470: Mobile App Development 12


S.N. Folder, File & Description
1 src
This contains the .java source files for your project. By default, it includes
anMainActivity.java source file having an activity class that runs when your app is
launched using the app icon.
2 gen
This contains the .R file, a compiler-generated file that references all the resources
found in your project. You should not modify this file.
3 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.
4 res/drawable-hdpi
This is a directory for drawable objects that are designed for high-density screens.
5 res/layout
This is a directory for files that define your app's user interface.
6 res/values
This is a directory for other various XML files that contain a collection of resources, such
as strings and colors definitions.
7 AndroidManifest.xml
This is the manifest file which describes the fundamental characteristics of the app and
defines each of its components.

3/13/2023 CIS 470: Mobile App Development 13


Coding Application
 Important parts of Android App
 Creating your first App

3/13/2023 CIS 470 Mobile App Development 14


Important parts of Android App
Important parts of an Android application include the
following:
o Activities
The Activities are the main Java classes, that contain
the Android code with which we are going to develop,
what do we want the application to do.
o Layouts
The Layouts are the main xml files, that contain the
Android xml code with which we are going to develop,
how will the application views look like.

3/13/2023 CIS 470: Mobile App Development 15


Creating your first Android App
 File -> New->New Project
 Name the app: HelloWorld
 Then select default option for all remaining steps

3/13/2023 CIS 470: Mobile App Development 16


Creating your first Android App

3/13/2023 CIS 470: Mobile App Development 17


Creating your first Android App

3/13/2023 CIS 470: Mobile App Development 18


Creating your first Android App

3/13/2023 CIS 470: Mobile App Development 19


Creating your first Android App

3/13/2023 CIS 470: Mobile App Development 20


Launching your first Android App

Select Run ➪ Run app from the Android Studio menu bar. You should
see the Select Deployment Target dialog shown below:

3/13/2023 CIS 470: Mobile App Development 21


3/13/2023 CIS 470: Mobile App Development 22
Using Code Completion
 Code completion: a tool that shows contextual options for
completing the piece of code that you are trying to write
 Example:
 In the editor tab for the MainActivity.java file, locate the line that

reads
 setContentView(R.layout.activity_main);

 Place your cursor after this line and press the Enter key. On the

new line, type the letter R, and then type a period, as shown here:
 R.

 Android Studio Code Completion should display a list of values

that you could use to try to complete the code statement

3/13/2023 CIS 470 Mobile App Development 23


Code completion example

If the code completion window does not open, press Ctrl+Space to force it to open.

3/13/2023 CIS 470 Mobile App Development 24


Debugging Your Application
 Setting Breakpoints
 Navigating paused code

3/13/2023 CIS 470 Mobile App Development 25


Setting Breakpoints
 Common way to debug: set breakpoints to help you find
what is going on with your code
 Breakpoints are a mechanism by which you can tell
Android Studio to temporarily pause execution of your
code, which allows you to examine the condition of your
application
 You can check on the values of variables in your application while
you are debugging it
 You can check whether certain lines of code are being executed
as expected—or at all

3/13/2023 CIS 470 Mobile App Development 26


Click the margin of the editor tab next to line of code you want to break at, to set a
breakpoint. A red circle is placed in the margin, and the corresponding line is
highlighted in red (clicked it again to remove the breakpoint)

Method A method breakpoint is represented by a red circle


Breakpoint containing four dots placed at the method signature
Android Studio pauses execution when the method is hit, and it
also automatically sets a corresponding breakpoint and pauses
at the end of the method

3/13/2023 CIS 470 Mobile App Development 27


Temporary Breakpoints

Useful in a loop

To set a temporary breakpoint, place your


cursor at the location in the code where you
want it to break and select Run ➪ Toggle
Temporary Line Breakpoint.

Android Studio only stops at this breakpoint the


first time your code enters it

3/13/2023 CIS 470 Mobile App Development 28


Conditional Breakpoints

A condition breakpoint is a breakpoint at which


Android Studio only pauses when specific conditions
are met.

To set a conditional breakpoint, first set a simple


breakpoint at the line of code you want to examine,
then right-click the simple breakpoint to bring up the
condition context menu

You would then set the condition in the breakpoint


such as: foo == true

3/13/2023 CIS 470 Mobile App Development 29


Navigating Paused Code

When Android Studio hits, and pauses at, a breakpoint, the red
circle in the margin next to the corresponding line of code
changes to a circle with a check mark

Once a breakpoint has been hit, the debug window


opens at the bottom of Android Studio

Step Over and Step Into

3/13/2023 CIS 470 Mobile App Development 30


Publishing Your Application
 Involves deploying your application to Google Store for others to use
or enjoy
 You must first generate Android Application Package (APK)
 APK is a compiled and executable version of your application
 Signing it identifies application developer to Google and users who
will be installing the application

3/13/2023 CIS 470 Mobile App Development 31


3/13/2023 CIS 470: Mobile App Development 32

You might also like