I know the basics of debugging, and I know I can add watches to a variable that stop the program\'s execution on a given condition. But I didn\'t want to stop the program every
If you know the basics of debugging, you can easily add watches to a variable that stop the program's execution on a given condition. If you didn't want to stop the program every time you want to see the value of a variable then the easy way to see the value of a variable is to use Toasts. A toast provides a sample value of any variable in an operation in a small popup. Toasts automatically disappear after a set timeout.
A simple code example:
Context context = getApplicationContext();
CharSequence text = "Hello toast!";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
In order to see the variable value in a Toast:
int var=1;
Toast.makeText(getApplicationContext(), "vlaue is "+var, Toast.LENGTH_LONG).show();
In order to see the variable type in a Toast:
Toast.makeText(getApplicationContext(), "type is "+var.getClass().getName(), Toast.LENGTH_LONG).show();