Break on variable value change in Android Studio 1.1.0?

后端 未结 4 1300
傲寒
傲寒 2021-02-03 22:58

I know I could set a breakpoint at every line where my code changes the variable, but is there an option such as right-clicking a variable (to \"Add to Watches\") that would sto

相关标签:
4条回答
  • 2021-02-03 23:24

    If the goal is simply to set a watchpoint where execution halts if a variable's value changes, there are two methods:

    Pressing Ctrl-shift-F8 to set a watchpoint brings up this dialog:

    That looks more powerful but it's confusing because it lacks the option I need; and there's an extra step: filling in the dialog box below:

    Once you fill it in correctly, you get the same options for stopping execution as in the simpler method below:

    1. Define the variable on one line ending with a semicolon.
    2. Left-click in the area where you set a normal breakpoint and up pops a dialog box.
    3. Choose options to suit your needs.

    Any instance where the value of the variable prefDbExists changes, execution will pause as at any "normal" (unconditional) breakpoint. And that's all I needed when I asked the original question.


    EDIT: Fully qualified class name is {package name}.{class name})

    0 讨论(0)
  • 2021-02-03 23:24

    What you seek for is commonly known as "WatchPoint". You will find detailed answer and examples on the doc. page of JetBrains - IntelliJ - Idea which is the basis for Android Studio.

    https://www.jetbrains.com/help/idea/2016.3/creating-field-watchpoints.html

    For me this works perfectly !

    0 讨论(0)
  • 2021-02-03 23:29

    Add a Kotlin Field Watchpoint by clicking on the space next to the line number for the field declaration in Android Studio. Select Kotlin Field Watchpoint from the Set Breakpoint menu. You will now get a breakpoint whenever that value changes.

    0 讨论(0)
  • 2021-02-03 23:32

    You can break on value changes of some variables in Android Studio 1.1.0.

    Android Studio calls them 'Java Field Watchpoints'.

    From the breakpoints windows, (Run -> "View breakpoints...") or Ctrl+Shift+F8, you can add "Java Field Watchpoints" from the plus in the top left corner, and then select your class and variable.

    0 讨论(0)
提交回复
热议问题