Reputation: 813
Scenario : I have a variable and I want to find out where and when the variable gets for example the value 4. When this happens the debugger should stop at that line.
Is this possible with Android Studio ?
Upvotes: 1
Views: 1712
Reputation: 611
If I understand correctly what you're wanting to do is set what is called a "Watchpoint" in Android Studio, and here's a link to the IntelliJ documentation that discusses them:
https://www.jetbrains.com/help/idea/2016.3/creating-field-watchpoints.html
In particular, what you want to do is set a break-point on the member variable itself, right-click that break-point and set the watch on "field modification" and set a condition for when that variable becomes the specific value you're trying to find.
So, in this simple bit of code:
public class MainActivity extends AppCompatActivity
{
int mWatchMe = -10;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
for (int i=0 ; i<20 ; i++)
{
mWatchMe++;
}
}
}
You would set a break-point on the line: int mWatchMe = -10;
.
Set the "Condition" and "modification" fields:
The execution should break where ever "mWatchMe" is set to '0':
Upvotes: 7
Reputation: 4451
This is possible. Right click on your breakpoint and then enter your expression "value == 4" in the condition field.
Upvotes: 2