In this method i set mode to 1;
bTouch.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
mode1=1;
Intent startGame = new Intent(
"com.example.mygame.GFXSurface");
startActivity(startGame);
}
});
when i call that mode in other class in onTouch method returns 0
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
GameSurface gamesurface = new GameSurface(this);
Mode mode2 = new Mode();
mode= mode2.mode1;
if (mode == 1){ // this should be 1 but is 0
x = event.getX();
y = event.getY();
Anyone know the solution on how to do that?
No,
mode1values is not 1, It should be 0.Just look at these two code lines..
Now from 1 code line
Mode mode2 = new Mode();you are creating a new Class
Modeobjectmode2.As per the class object initializing rules you are allocated a memory for a new Mode class. So all its member variables and fields are initializing to with new mwmory.
Now come on code line 2
you are accessing
mode1member field of newly created classModewith objectmode2.So how it can hold the old value 1? (Think again)
Either make a member field
mode1as a static and directly access the field with class Name,like,
Mode.mode1Or use the same object for retrieving (get) value of mode1 from which you set the value for mode1.