Étant donné la vue personnalisée simplifiée ci-dessous, qu'est-ce qui est/n'est pas exécuté sur le thread principal?Qu'est-ce qui ne fonctionne pas sur le thread principal?
// 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(){
// ...
}
}
est tout CustomView
en cours d'exécution sur un thread séparé?