The variable behaves strangely ... changes its value somewhere, although it should not. All sections of the code where the variable is used are furnished with breakpoints. Nothing helps, the brain is already boiling.

I want to set a breakpoint on the "change value" event of a variable. Is there an AS? Those. if the variable changes the value, the breakpoint is triggered.

upd: Watch I know. I still can not track. We need exactly the event to change the value.

upd2: Variable of int type, registered in Activity. In fact, it has two important states, before the ContextMenu is called, the variable is initiated. After selecting an action in ContextMenu, the variable is used.

Everything works fine until you turn the screen. Some miracles begin. I also initiate a variable (before calling ContextMenu), but after calling ContextMenu, its value is reset. Why and who does it, I can not understand.

Once again, before turning the screen upside down - everything is fine. At the time of the screen flip, all variables are carefully saved and restored when the Activity becomes active.

upd3.

Activity class ad:

int selectItemPosition = -1; 

Before Context Menu I assign the value:

 selectItemPosition = (int) ib.getTag(); 

where ib is an ImageButton. I assign the tag to it in the ListView custom adapter when I am drawing this ImageButton (I have it in every ListView item). It is the ImageButton that calls the context menu.

After selecting the desired action in the context menu, I use:

 mainAdapter.setFavorite(selectItemPosition); 

And just when used, selectItemPosition becomes -1. Although, before the context menu was called, everything was fine. selectItemPosition matched the position in the list that caused the menu.

Once again. Before turning the screen, everything works. But after turning this mess ...

  • Give the ad code and the variable changes, otherwise there will be a fortune telling on the coffee grounds. In general, it is better to call it a class field. - xkor
  • Thank you, correct :) I gave a description of the announcement of the field, changes and future use. I process the screen rotation like this, although this does not concern this variable, but, for example, I save the adapter in this way. - AndreyEKB
  • After the screen is rotated, you apparently have the ImageView re-created and the tag is not assigned to it - xkor
  • No, that's the thing. The value is assigned before ContextMneu and I check it (everything is fine, ImageView stores Tag). But then, something happens and after the ContextMneu is closed, the value changes ... nothing but witchcraft. - AndreyEKB
  • In general, I found a solution to the problem (but did not understand what it was). In place of a field of type int, created a class that contains this field and a getter and setter to access it. I added this class as a field in the Activity and save this class when converting the Activity. Everything began to work and the values ​​do not change ... - AndreyEKB

1 answer 1

Breakpoints can be placed only on specific lines. In this case, you can set them some conditions under which they will or will not work. In your case, I think it would be most convenient to hide the change of the variable behind the setter, that is, to change it only by calling the setter method, put the bryak inside this setter and either set the triggering condition — changing the value — or just add a condition to the method’s body and put the bryak inside this condition .

  • Thank! A good way - will put into service. But here the situation is different (see upd2), I know where the variable changes in my code ... but apparently something happens to it and I do not control it. So I need to understand the environment at the time of changing the value. - AndreyEKB