Kenji Kenji - 1 month ago 8
Android Question

is there any way to conditional Debugging in android studio

is there any way to have conditional Debug in android studio?
for example I wanna go to debug mode when a specific variable value is.
for example:

for(MyClass myclass: ClassList){
String title = myclass.gettitle(); // this is where break point is
}


before that I do not need the debug mode. I just wanna examine the app on that exact value. for example when
title="KickBoxing
" in this case I should check the variable value and if it is not my required value I should press F9 to go to next value. maybe this takes 50 times to get to my desired value.

I already know that I can put a condition in code and put breake point in that

for(MyClass myclass: ClassList){
String title = myclass.gettitle();
if(title.equals("kickBoxing"){
//put break point here
}
}


but I think this is not good and clean way and for each condition you had to change your code. I wonder if I could pop debug mode in condition it will be very exiting.

Answer

It is possible to add a condition for a breakpoint. Add a breakpoint, as you normally do, and click with the right mouse button on it. You will be prompt with a dialog. In the condition you can put some java code.

E.g. you could put "kickBoxing".equals(title)

this way the debugger will stop on that breakpoint only when the condition is true.

enter image description here

(photo taken from http://javafortesters.com/)

Comments