1

Please tell me if this approach is safe or what i can use instead of a plain Thread to safely dispatch Touch Events to my activity, for the purpose of testing the entire flow witch triggers from that onTouch() method.

//this is the thread which fires Touch Events to my main activity
public class Monkey extends Thread {

    Run r;
    float x,y;
    public Monkey (Run a)
    {
        r = a;
    }

    public void run()
    {
        int i = 0;
        while(i<10000)

        {
            r.onTouch(r.geView(),
                MotionEvent.obtain(SystemClock.uptimeMillis(), 
                SystemClock.uptimeMillis(), 2, x++, y++, 0));
        }
    }
}

// and this is the main activity
public class Run extends Activity implements OnTouchListener{
    private GLSurfaceView glSurface;

    public View geView()
    {
        return glSurface;
    }

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        glSurface = new GLSurfaceView(this);
        glSurface.setOnTouchListener(this);
        setContentView(glSurface);
        m = new Monkey(this);
    }

    public boolean onTouch(View v, MotionEvent event) 
    {
        //if from here i make other calls to classes that update my glsurface will my application eventualy crash?
    }
}
DIF
  • 2,470
  • 6
  • 35
  • 49

1 Answers1

1

Make use of singleton class

Singleton architecture

Sai mukesh
  • 712
  • 3
  • 9