Android Studio

How to debug project, Android Studio

Android Studio: Debug Project

This post is for beginners, to give basic understanding to debug project in Android Studio.

To debug Project, you have to place breakpoints at the code line, of a method or class, So the debugger will stop at that break point while debugging.
To place a break point just click on  work space left side border you can see red dot. To remove breakpoint just click on red dot again.

debug project 2

To debug a project from starting screen of your app, You have to click on the Debug menu button, or Press Shift+ F9

debug_1
*generally, while debugging app slows down.

So, You can use another debug option to debug at a Specific Screen.
At times you may want to debug code in a Specific screen at a particular line for eg. on a Save button click event method.

So, Place a breakpoint at that particular onClick(View v) method.

debug project 4

And just run the app by clicking Run menu button

debug_3

After running app on device or emulator, navigate to the Specific screen and just before clicking on Save button(button event where you want to debug code) in screen. Click on Attach debugger to Android Process menu button in Android Studio work space.

debug_5

You’ll see a dialog to select a process, here select your process (and wait for a moment for debugger to attach to process) and now click on the Save button in that Specific screen. You can see Debug console at the bottom and debugger waits at break point at a specific line to enable you start debugging.

debug project

Here I just like to explain few useful debug console button functionalities

Press F8 or click on the below debug console button icon, to move debugger to next line.. and so on…

debug project 7

Press F7 or click on the below debug console button icon, to move debugger to in to a inner class method.(This is very rarely used). Use it whenever a method call is escaping from debugging.

debug_8

Press F9 or click on the below debug console button icon, to execute code up to next break point..

debug project 9

Press Ctrl+F2 or click on the below debug console button icon, to stop debugger execution, when you click on this button, debugger stops execution and app runs normally.

debug_10

these buttons are mainly used for debugging. If you understand these button functions first then You can see and understand other button functions easily.

You can see all variables data and instances data of Specific screen in Variable section…

debug project 11

Hope it makes sense and helps somebody.

cheers 🙂

You may also interested in

 

One thought on “How to debug project, Android Studio

Leave a Reply

Your email address will not be published.