Android 通过从另一个线程调用onTouch()方法,我可以安全地将触摸事件分派到主活动吗?

Android 通过从另一个线程调用onTouch()方法,我可以安全地将触摸事件分派到主活动吗?,android,testing,android-activity,touch-event,monkey,Android,Testing,Android Activity,Touch Event,Monkey,请告诉我这种方法是否安全,或者我可以使用什么代替普通线程来安全地将触控事件分派到我的活动中,以便测试整个流witch从onTouch()方法触发 //这是向我的主要活动触发触摸事件的线程 公共类Monkey扩展线程{ 运行r; 浮动x,y; 公猴(跑a) { r=a; } 公开募捐 { int i=0; 而(i使用单例类 使用singleton类 //this is the thread which fires Touch Events to my main activity public c

请告诉我这种方法是否安全,或者我可以使用什么代替普通线程来安全地将触控事件分派到我的活动中,以便测试整个流witch从onTouch()方法触发

//这是向我的主要活动触发触摸事件的线程
公共类Monkey扩展线程{
运行r;
浮动x,y;
公猴(跑a)
{
r=a;
}
公开募捐
{
int i=0;

而(i使用单例类


使用singleton类

//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?
    }
}