0
아래의 단순화 된 사용자 정의보기가 주어지면 주 스레드에서 정확히 실행되고 있지 않습니까?메인 스레드에서 실행되지 않는 항목은 무엇입니까?
// MainActivity
protected void onCreate(Bundle bundle) {
// ...
CustomView customView = new CustomView(this);
setContentView(customView);
customView.setOnTouchListener((v, event) -> {
customView.setPoint(event.getX(), event.getY());
});
}
public class CustomView extends SurfaceView implements SurfaceHolder.Callback, Runnable {
protected Thread thread;
private boolean running;
private int x;
private int y;
public CustomView(Context context) {
super(context);
thread = new Thread(this);
}
public void run() {
// Get SurfaceHolder -> Canvas
// clear canvas
// draw circle at point <x, y>
// Do some IO?
longRunningMethod();
}
public void surfaceCreated(SurfaceHolder holder) {
running = true;
thread.start();
}
public void surfaceDestroyed(SurfaceHolder holder) {
running = false;
}
public void setPoint(int x, int y) {
this.x = x;
this.y = y;
run();
}
private void longRunningMethod(){
// ...
}
}
모두 CustomView
은 별도의 스레드에서 실행됩니까? 다른
public void run() {
// Get SurfaceHolder -> Canvas
// clear canvas
// draw circle at point <x, y>
// Do some IO?
longRunningMethod();
}
모두가 메인 스레드에 : 여기에 별도의 스레드에