안드로이드 개발 질문/답변
(글 수 45,052)
많은 코드는 생략하고 대락 이렇습니다.
oncreate에 핸들러가 있고 터치이벤트가 발생하면 threadFunction() 함수로 들어가서 thread를 발생 시키고 handler에 들어가서
강제로 터치 이벤트를 발생 시키는 구조 입니다. 그런데
07-17 21:19:55.207: E/AndroidRuntime(26722): java.lang.RuntimeException: This method can not be called from the main application thread
라는 에러가 납니다 왜 그런가여?? ㅠㅠ
해결 방안좀 가르쳐 주세여 ㅋ
onCreate(){
mHandler = new Handler() {
public void handleMessage(Message msg) {
super.handleMessage(msg);
Instrumentation ist = new Instrumentation();
long downTime = SystemClock.uptimeMillis();
long eventTime = SystemClock.uptimeMillis();
MotionEvent event = MotionEvent.obtain(downTime, eventTime,
MotionEvent.ACTION_DOWN, 100,100, 0);
MotionEvent event2 = MotionEvent.obtain(downTime, eventTime,
MotionEvent.ACTION_UP, 100, 100, 0);
ist.sendPointerSync(event);
ist.sendPointerSync(event2);
return;
}
};
}
public void threadFunction(){
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
mHandler.sendEmptyMessage(0);
}
});
thread.start();
}