Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to put a watch (see how a variable is modified) in Android Studio?

I don't know how to use a watch in Android Studio. I want to see how the value of a variable modifies through debugging. Does anyone know how to do this?

like image 444
uwe seeler Avatar asked Jul 31 '14 11:07

uwe seeler


People also ask

Is it possible to add Watches in a program to see how the values of variables are updated during execution?

YES you can! In other words, you can view variable changes at run time!

How do you watch a variable in Java?

Setting a Watch on a Variable, Field, or Other Expression To set a watch on an identifier such as a variable or field, right-click the variable or field in the Source Editor and choose New Watch. The identifier is then added to the Watches window. To create a watch for another expression: Choose Run | New Watch.

How can the value of a variable be modified while debugging?

You can change a variable in the Evaluate dialog or in the Watch List panel. The Evaluate dialog: To invoke the dialog, press the Call the Evaluate Dialog button on the Debug toolbar, or press the Ctrl+F12 shortcut (this is the default shortcut. You can change it any time.


1 Answers

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.

enter image description here

Keep debugging and you should see the variable from the Watches window frame update when appropriate based on your code.

enter image description here

like image 191
Miguel Avatar answered Sep 21 '22 18:09

Miguel