SlideShare a Scribd company logo
2
Most read
4
Most read
ANDROID
DEVELOPMENT
SESSION 5 – DEBUGGING WITH ANDROID STUDIO
AHMED EZZ EL - DIN
facebook.com/ahmed.e.hassan
1
SESSION CONTENT
• Introduction
• Run your App in Debug Mode.
• Use system Log
• Work with Breakpoints
• Track object Allocation
• Capture Screenshots and Videos
facebook.com/ahmed.e.hassan
2
INTRODUCTION
facebook.com/ahmed.e.hassan
3
Android Studio enables you to debug apps running on the emulator or on an
Android device. With Android Studio, you can:
• Select a device to debug your app on.
• View the system log.
• Set breakpoints in your code.
• Examine variables and evaluate expressions at run time.
• Run the debugging tools from the Android SDK.
• Capture screenshots and videos of your app.
RUN YOUR APP IN
DEBUG MODE
facebook.com/ahmed.e.hassan
4
To run your app in debug mode, you build an APK signed with a debug key and install it on
a physical Android device or on the Android emulator
To debug your app in Android Studio:
1. Open your project in Android Studio.
2. Click Debug in the toolbar.
3. On the Choose Device window, select a hardware device from the list or choose a
virtual device.
4. Click OK. Your app starts on the selected device.
facebook.com/ahmed.e.hassan
5
RUN YOUR APP IN
DEBUG MODE
Android Studio opens the Debug tool window when you debug your app.
To open the Debug window manually, click Debug
This window shows threads and variables in the Debugger tab, the device status
in the Console tab, and the system log in the Logcat tab.
facebook.com/ahmed.e.hassan
6
RUN YOUR APP IN
DEBUG MODE
Attach the debugger to a running process
You don't always have to restart your app to debug it. To debug an app that you're
already running:
1. Click Attach debugger to Android process .
2. In the Choose Process window, select the device and app you want to attach the
debugger to.
3. To open the Debug tool window, click Debug
USE THE SYSTEM LOG
facebook.com/ahmed.e.hassan
7
The system log shows system messages while you debug your app.
These messages include information from apps running on the device.
If you want to use the system log to debug your app, make sure your code writes log
messages and prints the stack trace for exceptions while your app is in the
development phase.
facebook.com/ahmed.e.hassan
8
USE THE SYSTEM LOG
During development, your code can also catch exceptions and write the stack trace to the
system log:
facebook.com/ahmed.e.hassan
9
USE THE SYSTEM LOG
View the system log
To view the system log on the Android DDMS tool window:
1. Start your app .
2. Click Android to open the Android DDMS tool window.
3. If the system log is empty in the Logcat view, click Restart .
facebook.com/ahmed.e.hassan
10
USE THE SYSTEM LOG
The system log shows messages from Android services and other Android apps. To
filter the log messages to view only the ones you are interested in, use the tools in the
Android DDMS window:
• To show only log messages for a particular process, select the process in the Devices view and
then click Only Show Logcat from Selected Process . If the Devices view is not available,
click Restore Devices View on the right of the Android DDMS tool window. This button is
only visible when you hide the Devices window.
• To filter log messages by log level, select a level under Log Level on the top of the Android
DDMS window.
• To show only log messages that contain a particular string, enter the string in the search box
and press Enter.
WORK WITH
BREAKPOINTS
facebook.com/ahmed.e.hassan
11
Breakpoints enable you to pause the execution of your app at a particular line of
code, examine variables, evaluate expressions, and continue the execution line
by line.
Use breakpoints to determine the causes of run-time errors that you can't fix
by looking at your code only.
To debug your app using breakpoints:
1. Open the source file in which you want to set a breakpoint.
2. Locate the line where you want to set a breakpoint and click on it.
3. Click on the yellow portion of the side bar to the left of this line
4. Start your app
facebook.com/ahmed.e.hassan
12
WORK WITH
BREAKPOINTS
View and configure breakpoints
To view all the breakpoints and configure breakpoint settings, click View Breakpoints
on the left side of the Debug tool window. The Breakpoints window appears
facebook.com/ahmed.e.hassan
13
WORK WITH
BREAKPOINTS
Debug your app with breakpoints
After you set breakpoints in your code, click Rerun to start the app again.
When a breakpoint is hit, Android Studio pauses the app and highlights the breakpoint in
the source code.
• To examine the object tree for a variable, expand it in the Variables view. If the Variables view is not
visible, click Restore Variables View .
• To evaluate an expression at the current execution point, click Evaluate Expression .
• To advance to the next line in the code (without entering a method), click Step Over .
• To advance to the first line inside a method call, click Step Into .
• To advance to the next line outside the current method, click Step Out .
• To continue running the app normally, click Resume Program
facebook.com/ahmed.e.hassan
14
WORK WITH
BREAKPOINTS
TRACK OBJECT
ALLOCATION
facebook.com/ahmed.e.hassan
15
Android Studio lets you track objects that are being allocated on the Java heap and see
which classes and threads are allocating these objects. This allows you to see the list of
objects allocated during a period of interest. This information is valuable for assessing
memory usage that can affect application performance.
To track memory allocation of objects:
1. Start your app.
2. Click Android to open the Android DDMS tool window.
3. On the Android DDMS tool window, select the Devices | logcat tab.
4. Select your device from the dropdown list.
5. Select your app by its package name from the list of running apps.
6. Click Start Allocation Tracking
7. Interact with your app on the device.
8. Click Stop Allocation Tracking
facebook.com/ahmed.e.hassan
16
TRACK OBJECT
ALLOCATION
Android Studio shows the objects that the system allocated with the following information:
• Allocation order
• Allocated class
• Allocation size
• Thread ID
• Allocation method, class, and line number
• Stack trace at the point of allocation
CAPTURE SCREENSHOTS
AND VIDEOS
facebook.com/ahmed.e.hassan
17
Android Studio enables you to capture a screenshot or a short video of the device
screen while your app is running.
Screenshots and videos are useful as promotional materials for your app, and you can
also attach them to bug reports that you send to your development team.
To take a screenshot of your app:
1. Start your app.
2. Click Android to open the Android DDMS tool window.
3. Click Screen Capture on the left side of the Android DDMS tool window.
4. Optional: To add a device frame around your screenshot, enable the Frame screenshot option.
5. Click Save.
facebook.com/ahmed.e.hassan
18
CAPTURE SCREENSHOTS
AND VIDEOS
To take a video recording of your app:
1. Start your app.
2. Click Android to open the Android DDMS tool window.
3. Click Screen Record on the left side of the Android DDMS tool window.
4. Click Start Recording.
5. Interact with your app.
6. Click Stop Recording.
7. Enter a file name for the recording and click OK.

More Related Content

What's hot (20)

PDF
Android Security
Lars Jacobs
 
PDF
Android datastorage
Krazy Koder
 
PPT
Appium
Keshav Kashyap
 
PPT
Android application structure
Alexey Ustenko
 
PPTX
androidstudio.pptx
SundaresanB5
 
PDF
Introduction to java (revised)
Sujit Majety
 
PPTX
Creating the first app with android studio
Parinita03
 
PDF
Android Platform Architecture
Naresh Chintalcheru
 
PDF
Android resources
ma-polimi
 
PPTX
Android studio installation
Faysal Hossain Shezan
 
PDF
Android Location and Maps
Jussi Pohjolainen
 
PPTX
Exception Handling in Java
lalithambiga kamaraj
 
PPTX
Appium ppt
natashasweety7
 
PDF
Mobile Test Automation - Appium
Maria Machlowska
 
PDF
Data Persistence in Android with Room Library
Reinvently
 
PDF
Introduction to Android Development
Aly Abdelkareem
 
PPTX
Android Basic Concept
University of Potsdam
 
PPT
WPF
Vishwa Mohan
 
PDF
Introduction to ios
Swapnali Pawar
 
PPTX
Introduction to java
Saba Ameer
 
Android Security
Lars Jacobs
 
Android datastorage
Krazy Koder
 
Android application structure
Alexey Ustenko
 
androidstudio.pptx
SundaresanB5
 
Introduction to java (revised)
Sujit Majety
 
Creating the first app with android studio
Parinita03
 
Android Platform Architecture
Naresh Chintalcheru
 
Android resources
ma-polimi
 
Android studio installation
Faysal Hossain Shezan
 
Android Location and Maps
Jussi Pohjolainen
 
Exception Handling in Java
lalithambiga kamaraj
 
Appium ppt
natashasweety7
 
Mobile Test Automation - Appium
Maria Machlowska
 
Data Persistence in Android with Room Library
Reinvently
 
Introduction to Android Development
Aly Abdelkareem
 
Android Basic Concept
University of Potsdam
 
Introduction to ios
Swapnali Pawar
 
Introduction to java
Saba Ameer
 

Similar to Android development session 5 - Debug android studio (20)

PDF
ppt7_App Debug Framework_D2 to dowwnload.pdf
ubaidullah75790
 
PDF
Getting Started with Android Studio: A Step-by-Step Guide
Naresh IT
 
PPTX
Build Your First Android App
Transpose Solutions Inc
 
PPTX
Android software development – the first few hours
sjmarsh
 
PDF
Android app development guide for freshers by ace web academy
Ace Web Academy -Career Development Center
 
PDF
Homework seriesandroidworkshop JUly 12th
Rishi Kumar
 
DOCX
Hospital app project (how to upload app)
MAHFUZ RAIHAN
 
PDF
Appium- part 1
Mithilesh Singh
 
PDF
Dreamweaver cs5 read me
rubi hartanto
 
PDF
Dreamweaver cs5 read me
Php RedStorm
 
PDF
Dreamweaver cs5 read me
Bo Ei
 
PPTX
How to create android applications
TOPS Technologies
 
PDF
Dreamweaver cs5 read me
ok71
 
PPTX
How To Run/Test Flutter App On a Real Device?
RubenGray1
 
PDF
Getting started with appium
Pratik Patel
 
DOCX
5 Easy Steps to Learn Espresso
Raman Gowda Hullur
 
PPTX
How to build your own Android App -Step by Step Guide
Ace Web Academy -Career Development Center
 
PDF
PERTEMUAN 3_INTRO TO ANDROID APP DEV.pdf
arfa442827
 
PDF
Expert Guidance on debugging React Native Apps: Recommended Practices and Han...
Shelly Megan
 
PDF
Dev windows phone_apps_getting_started_guide
TrioBlack Trioblack
 
ppt7_App Debug Framework_D2 to dowwnload.pdf
ubaidullah75790
 
Getting Started with Android Studio: A Step-by-Step Guide
Naresh IT
 
Build Your First Android App
Transpose Solutions Inc
 
Android software development – the first few hours
sjmarsh
 
Android app development guide for freshers by ace web academy
Ace Web Academy -Career Development Center
 
Homework seriesandroidworkshop JUly 12th
Rishi Kumar
 
Hospital app project (how to upload app)
MAHFUZ RAIHAN
 
Appium- part 1
Mithilesh Singh
 
Dreamweaver cs5 read me
rubi hartanto
 
Dreamweaver cs5 read me
Php RedStorm
 
Dreamweaver cs5 read me
Bo Ei
 
How to create android applications
TOPS Technologies
 
Dreamweaver cs5 read me
ok71
 
How To Run/Test Flutter App On a Real Device?
RubenGray1
 
Getting started with appium
Pratik Patel
 
5 Easy Steps to Learn Espresso
Raman Gowda Hullur
 
How to build your own Android App -Step by Step Guide
Ace Web Academy -Career Development Center
 
PERTEMUAN 3_INTRO TO ANDROID APP DEV.pdf
arfa442827
 
Expert Guidance on debugging React Native Apps: Recommended Practices and Han...
Shelly Megan
 
Dev windows phone_apps_getting_started_guide
TrioBlack Trioblack
 
Ad

Recently uploaded (20)

PDF
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
PPTX
How to Configure Re-Ordering From Portal in Odoo 18 Website
Celine George
 
PDF
Mahidol_Change_Agent_Note_2025-06-27-29_MUSEF
Tassanee Lerksuthirat
 
PDF
Aprendendo Arquitetura Framework Salesforce - Dia 03
Mauricio Alexandre Silva
 
PPTX
Identifying elements in the story. Arrange the events in the story
geraldineamahido2
 
PDF
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
PDF
Horarios de distribución de agua en julio
pegazohn1978
 
PPTX
How to Create a Customer From Website in Odoo 18.pptx
Celine George
 
PPTX
infertility, types,causes, impact, and management
Ritu480198
 
PDF
Characteristics, Strengths and Weaknesses of Quantitative Research.pdf
Thelma Villaflores
 
PPTX
How to Send Email From Odoo 18 Website - Odoo Slides
Celine George
 
PDF
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
PDF
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
PPTX
Post Dated Cheque(PDC) Management in Odoo 18
Celine George
 
PDF
STATEMENT-BY-THE-HON.-MINISTER-FOR-HEALTH-ON-THE-COVID-19-OUTBREAK-AT-UG_revi...
nservice241
 
PPTX
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
PPTX
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
PPTX
How to Create Odoo JS Dialog_Popup in Odoo 18
Celine George
 
PDF
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
PDF
Governor Josh Stein letter to NC delegation of U.S. House
Mebane Rash
 
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
How to Configure Re-Ordering From Portal in Odoo 18 Website
Celine George
 
Mahidol_Change_Agent_Note_2025-06-27-29_MUSEF
Tassanee Lerksuthirat
 
Aprendendo Arquitetura Framework Salesforce - Dia 03
Mauricio Alexandre Silva
 
Identifying elements in the story. Arrange the events in the story
geraldineamahido2
 
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
Horarios de distribución de agua en julio
pegazohn1978
 
How to Create a Customer From Website in Odoo 18.pptx
Celine George
 
infertility, types,causes, impact, and management
Ritu480198
 
Characteristics, Strengths and Weaknesses of Quantitative Research.pdf
Thelma Villaflores
 
How to Send Email From Odoo 18 Website - Odoo Slides
Celine George
 
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
Post Dated Cheque(PDC) Management in Odoo 18
Celine George
 
STATEMENT-BY-THE-HON.-MINISTER-FOR-HEALTH-ON-THE-COVID-19-OUTBREAK-AT-UG_revi...
nservice241
 
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
How to Create Odoo JS Dialog_Popup in Odoo 18
Celine George
 
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
Governor Josh Stein letter to NC delegation of U.S. House
Mebane Rash
 
Ad

Android development session 5 - Debug android studio

  • 1. ANDROID DEVELOPMENT SESSION 5 – DEBUGGING WITH ANDROID STUDIO AHMED EZZ EL - DIN facebook.com/ahmed.e.hassan 1
  • 2. SESSION CONTENT • Introduction • Run your App in Debug Mode. • Use system Log • Work with Breakpoints • Track object Allocation • Capture Screenshots and Videos facebook.com/ahmed.e.hassan 2
  • 3. INTRODUCTION facebook.com/ahmed.e.hassan 3 Android Studio enables you to debug apps running on the emulator or on an Android device. With Android Studio, you can: • Select a device to debug your app on. • View the system log. • Set breakpoints in your code. • Examine variables and evaluate expressions at run time. • Run the debugging tools from the Android SDK. • Capture screenshots and videos of your app.
  • 4. RUN YOUR APP IN DEBUG MODE facebook.com/ahmed.e.hassan 4 To run your app in debug mode, you build an APK signed with a debug key and install it on a physical Android device or on the Android emulator To debug your app in Android Studio: 1. Open your project in Android Studio. 2. Click Debug in the toolbar. 3. On the Choose Device window, select a hardware device from the list or choose a virtual device. 4. Click OK. Your app starts on the selected device.
  • 5. facebook.com/ahmed.e.hassan 5 RUN YOUR APP IN DEBUG MODE Android Studio opens the Debug tool window when you debug your app. To open the Debug window manually, click Debug This window shows threads and variables in the Debugger tab, the device status in the Console tab, and the system log in the Logcat tab.
  • 6. facebook.com/ahmed.e.hassan 6 RUN YOUR APP IN DEBUG MODE Attach the debugger to a running process You don't always have to restart your app to debug it. To debug an app that you're already running: 1. Click Attach debugger to Android process . 2. In the Choose Process window, select the device and app you want to attach the debugger to. 3. To open the Debug tool window, click Debug
  • 7. USE THE SYSTEM LOG facebook.com/ahmed.e.hassan 7 The system log shows system messages while you debug your app. These messages include information from apps running on the device. If you want to use the system log to debug your app, make sure your code writes log messages and prints the stack trace for exceptions while your app is in the development phase.
  • 8. facebook.com/ahmed.e.hassan 8 USE THE SYSTEM LOG During development, your code can also catch exceptions and write the stack trace to the system log:
  • 9. facebook.com/ahmed.e.hassan 9 USE THE SYSTEM LOG View the system log To view the system log on the Android DDMS tool window: 1. Start your app . 2. Click Android to open the Android DDMS tool window. 3. If the system log is empty in the Logcat view, click Restart .
  • 10. facebook.com/ahmed.e.hassan 10 USE THE SYSTEM LOG The system log shows messages from Android services and other Android apps. To filter the log messages to view only the ones you are interested in, use the tools in the Android DDMS window: • To show only log messages for a particular process, select the process in the Devices view and then click Only Show Logcat from Selected Process . If the Devices view is not available, click Restore Devices View on the right of the Android DDMS tool window. This button is only visible when you hide the Devices window. • To filter log messages by log level, select a level under Log Level on the top of the Android DDMS window. • To show only log messages that contain a particular string, enter the string in the search box and press Enter.
  • 11. WORK WITH BREAKPOINTS facebook.com/ahmed.e.hassan 11 Breakpoints enable you to pause the execution of your app at a particular line of code, examine variables, evaluate expressions, and continue the execution line by line. Use breakpoints to determine the causes of run-time errors that you can't fix by looking at your code only. To debug your app using breakpoints: 1. Open the source file in which you want to set a breakpoint. 2. Locate the line where you want to set a breakpoint and click on it. 3. Click on the yellow portion of the side bar to the left of this line 4. Start your app
  • 12. facebook.com/ahmed.e.hassan 12 WORK WITH BREAKPOINTS View and configure breakpoints To view all the breakpoints and configure breakpoint settings, click View Breakpoints on the left side of the Debug tool window. The Breakpoints window appears
  • 13. facebook.com/ahmed.e.hassan 13 WORK WITH BREAKPOINTS Debug your app with breakpoints After you set breakpoints in your code, click Rerun to start the app again. When a breakpoint is hit, Android Studio pauses the app and highlights the breakpoint in the source code. • To examine the object tree for a variable, expand it in the Variables view. If the Variables view is not visible, click Restore Variables View . • To evaluate an expression at the current execution point, click Evaluate Expression . • To advance to the next line in the code (without entering a method), click Step Over . • To advance to the first line inside a method call, click Step Into . • To advance to the next line outside the current method, click Step Out . • To continue running the app normally, click Resume Program
  • 15. TRACK OBJECT ALLOCATION facebook.com/ahmed.e.hassan 15 Android Studio lets you track objects that are being allocated on the Java heap and see which classes and threads are allocating these objects. This allows you to see the list of objects allocated during a period of interest. This information is valuable for assessing memory usage that can affect application performance. To track memory allocation of objects: 1. Start your app. 2. Click Android to open the Android DDMS tool window. 3. On the Android DDMS tool window, select the Devices | logcat tab. 4. Select your device from the dropdown list. 5. Select your app by its package name from the list of running apps. 6. Click Start Allocation Tracking 7. Interact with your app on the device. 8. Click Stop Allocation Tracking
  • 16. facebook.com/ahmed.e.hassan 16 TRACK OBJECT ALLOCATION Android Studio shows the objects that the system allocated with the following information: • Allocation order • Allocated class • Allocation size • Thread ID • Allocation method, class, and line number • Stack trace at the point of allocation
  • 17. CAPTURE SCREENSHOTS AND VIDEOS facebook.com/ahmed.e.hassan 17 Android Studio enables you to capture a screenshot or a short video of the device screen while your app is running. Screenshots and videos are useful as promotional materials for your app, and you can also attach them to bug reports that you send to your development team. To take a screenshot of your app: 1. Start your app. 2. Click Android to open the Android DDMS tool window. 3. Click Screen Capture on the left side of the Android DDMS tool window. 4. Optional: To add a device frame around your screenshot, enable the Frame screenshot option. 5. Click Save.
  • 18. facebook.com/ahmed.e.hassan 18 CAPTURE SCREENSHOTS AND VIDEOS To take a video recording of your app: 1. Start your app. 2. Click Android to open the Android DDMS tool window. 3. Click Screen Record on the left side of the Android DDMS tool window. 4. Click Start Recording. 5. Interact with your app. 6. Click Stop Recording. 7. Enter a file name for the recording and click OK.