나는 android에서 새롭다. 당신은 우리가 볼 수 있듯이UI 스레드 및 Surfaceview
class LunarView extends SurfaceView implements SurfaceHolder.Callback {
//...
public LunarView(Context context, AttributeSet attrs) {
class LunarThread extends Thread {
//...
private void doDraw(Canvas canvas) {
//do some drawing on the canvas
}
}
//...
public LunarView(Context context, AttributeSet attrs) {
super(context, attrs);
// ...
// create thread only; it's started in surfaceCreated()
thread = new LunarThread(holder, context, new Handler() {
@Override
public void handleMessage(Message m) {
mStatusText.setVisibility(m.getData().getInt("viz"));
mStatusText.setText(m.getData().getString("text"));
}
});
//...
}
//...
}
: 당신이 안드로이드 SDK의 LunarLander 샘플을 보면,이 코드를 볼 수 있습니다
1 : Do not block the UI thread
2 : Do not access the Android UI toolkit from outside the UI thread
: 나는 안드로이드 개발자 웹 사이트에서 안드로이드 스레딩에 대한 두 가지 규칙을 보았다 뷰를 렌더링하고있는 새로운 thread를 작성합니다.
이 코드가 안드로이드 프레임 워크의 스레딩 2 규칙을 위반하지 않는 이유는 무엇입니까?
읽어 주셔서 감사합니다.
네, 링크 해 주셔서 감사합니다. –
다른 스레드에서 렌더링 할 수 있습니다. 이것은 예제의 핵심입니다 : * 나중에 * MainUI로 전송 된 캔버스에 쓰는 두 번째 스레드를 생성하십시오. – RichieHH