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

01 Android Studio

Uploaded by

fsabooh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

01 Android Studio

Uploaded by

fsabooh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 18

CIS 470

Mobile App Development

Lecture 2

Wenbing Zhao
Department of Electrical Engineering and Computer Science
Cleveland State University
[email protected]

10/20/2024 CIS 470 Mobile App Development 1


Using Android Studio for
Android Development
 How to move around in the Integrated
Development Environment (IDE)
 How to use code completion to make writing
applications easier
 How to use breakpoints to debug your
applications

10/20/2024 CIS 470 Mobile App Development 2


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

10/20/2024 CIS 470 Mobile App Development 3


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

10/20/2024 CIS 470 Mobile App Development 4


10/20/2024 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

10/20/2024 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

10/20/2024 CIS 470 Mobile App Development 7


The Android Studio IDE

10/20/2024 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.

10/20/2024 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.

10/20/2024 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.

10/20/2024 CIS 470 Mobile App Development 11


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

10/20/2024 CIS 470 Mobile App Development 12


Code completion example

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

10/20/2024 CIS 470 Mobile App Development 13


Debugging Your Application
 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

10/20/2024 CIS 470 Mobile App Development 14


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

10/20/2024 CIS 470 Mobile App Development 15


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

10/20/2024 CIS 470 Mobile App Development 16


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

10/20/2024 CIS 470 Mobile App Development 17


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

10/20/2024 CIS 470 Mobile App Development 18

You might also like