I know the basics of debugging, and I know I can add watches to a variable that stop the program's execution on a given condition. But I didn't want to stop the program every time I need to see the value of a variable. Neither I want to log the value of every relevant variable into logcat... I only wanted to see their values like I do at breakpoints, only in runtime.
I'm programming Android, in Android Studio.
Thanks for the help!
Hover over a variable to see its value. The most commonly used way to look at variables is the DataTip. When stopped in the debugger hover the mouse cursor over the variable you want to look at. The DataTip will appear showing you the value of that variable.
To open the Locals window, while debugging, select Debug > Windows > Locals, or press Alt+4. This topic applies to Visual Studio on Windows.
When your program has stopped on a breakpoint click the icon at the far right of the debugger menu (see image below). You can type in methods or variable names into this window and see what they would be.
You can type any expression you like (as long as it is within the scope of where you broke your code) and input any hard-coded values or objects all without re-running your project.
To add a variable to your watch list
Start by putting a break point in the class where you'd want to watch a specific variable. Run the code and once it hits your breakpoint from the Variables window frame you should see all of the variables that are accessible. Simply choose the one you'd want to watch and then right click and choose "Add to watches" from the drop-down.
Keep debugging and you should see the variable from the Watches window frame update when appropriate based on your code.
According to the Android Dev Summit '19, you can easily do that by disabling the Suspended
flag in your breakpoint.
Then you can evaluate a log message to the console every time it gets the breakpoint, without suspending!
As you can see, my app fires a log to the console every time it gets to my breakpoint.
In other words, you can view variable changes at run time!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With