Debugger mode on Android Studio

Ankit Goyal
Nerd For Tech
Published in
4 min readJun 27, 2020

--

I am back with a story of another Android Studio tool (most of Intellij based IDEs). In my previous story we have seen multiple advanced options of breakpoint 🔴 this time we will be looking into how to utilize the debug mode on Android Studio. This story will be broken into 3 parts:

  • Basic
  • Advance
  • Make life easy

Basic

To enter into a debug mode you need to put at least 1 breakpoint into your app code and after that, you need to either run your code in debugger mode or attach a debugger with a running app on your emulator or device.

Once your app hit a breakpoint you will see a debugger window will popup like below

debugger mode

Basic commands include

Run over
  • Run over:- go to the next line of code.
Step into
  • Step into:- go into a method/ function, (note:- it creates the arguments first.)
Step out
  • Step out:- come out of any method/function.
Run to cursor
  • Run to cursor:- This might be a confusing one but it takes the execution to your cursor’s current position.
Show execution point
  • Show execution point:- If you have moved somewhere in the code, this will take you to the current execution point.

Advance

Let’s talk about some of the advanced topics which will make your life easy and debugging will be fun.

  • Inspect an object
  • Evaluate Expression
  • Change the value of a variable
  • Throw an exception forcefully from a method

Inspect an object

Using this you can see values of all class level variables inside any object.

Once you click on inspect a new popup will open like below which will give you entire information about the object like values of all class variables etc.

Inspect popup window

here you can change some of the variable values(in Kotlin if a variable is declared as val you can not change its value)

Evaluate Expression

To run any code during debugging you can use the Evaluate Expression option. This will allow you to execute any code which can be multiline or all together in a different language also.

Throw an exception

From Frames pane, you can force a method to throw an exception. On Intellij website they have mentioned about another option where you can force return a value before return statement of the method but the same option is not available in Android studio(I am using version 3.5.1)

After right click on method name

Make life easy

Debugger mode helps a developer to find the flow of the code but it needs a lot of concentration and many times it shows a lot of information which you may not be interested at that time so how to make our life easy and fun while working. For this Watcher is here to help us.

Watcher

Watcher allows you to concentrate on the problem you are solving and remove clutter from the screen.

Whatever variable you interested just drag and drop them into watcher pane and you can do any operations on them which you can do in the variable pane.

Watcher pane after selecting few variable

in this case, I was interested in DOB, Contact Numbers, education, and family name of any candidate so I have moved them into watcher pane and close the variable pane. Now to make some items from my watch list more prominent and readable I have labeled them using Mark Object option.

Right click on any variable and select mark object
After selecting mark object a new popup where you can change the name and color
post giving a label and a different color

I hope this article helped you understand debugger on Android Studio or any other IntelliJ based IDE better and make your life easy. If you like it then give me some 👏 and put some comments so I can improve my upcoming stories.

--

--

Ankit Goyal
Nerd For Tech

Android Platform team member at Walmart Global Tech