Is it possible to view variables at runtime?

I know the basics of debugging, and I know that I can add hours to a variable that stops the program from executing under a given condition. But I did not want to stop the program every time I needed to see the value of a variable. I also do not want to register the value of each corresponding variable in logcat ... I just wanted to see their values, as I do at breakpoints, only at runtime.

I am programming Android in Android Studio.

Thanks for the help!

+5
source share
1 answer

When your program stops at a breakpoint, click the icon to the right of the debugger menu (see the figure below). You can enter methods or variable names in this window and see what they will be.

enter image description here

You can enter any expression that you like (as long as it is within the area where you violated the code), and enter any hard-coded values โ€‹โ€‹or objects without restarting your project.

enter image description here

To add a variable to the watchlist

Start by placing a breakpoint in the class where you want to see a specific variable. Run the code, and as soon as it reaches the breakpoint from the window of the variable window, you will see all the available variables. Just select the one you want to watch, and then right-click and select "Add to watch" from the drop-down list.

enter image description here

Keep debugging, and you should see a variable from the update window of the clock window, when necessary, based on your code.

enter image description here

+6
source

Source: https://habr.com/ru/post/1233874/


All Articles