Ho un'applicazione Android che aggiorna lo schermo ogni 33 millisecondi, visualizzando un rettangolo a una coppia di coordinate. Ecco il codice per la visualizzazione personalizzata:WaitingInMainSignalCatcherLoop Errore nell'applicazione Android
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.os.Handler;
import android.util.AttributeSet;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
public class OurView extends SurfaceView implements SurfaceHolder.Callback {
private SurfaceHolder holder;
private Handler handler = new Handler();
private Bitmap testimg;
private int xCoord = 500;
private int yCoord = 500;
boolean running = false;
int xPos;
int yPos;
public OurView(Context context) {
super(context);
init();
}
public OurView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public OurView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init();
}
private void init() {
holder = getHolder();
holder.addCallback(this);
testimg = BitmapFactory.decodeResource(getResources(),R.drawable.testimg);
}
void moveImage(int xChange, int yChange) {
this.xCoord = this.xCoord + xChange;
this.yCoord = this.yCoord + yChange;
}
void doDraw(Canvas canvas) {
xPos = this.xCoord + (testimg.getWidth()/2);
yPos = this.yCoord + (testimg.getHeight()/2);
canvas.drawARGB(255, 55, 255, 255);
canvas.drawBitmap(testimg, xPos, yPos, null);
}
@Override
public void surfaceCreated(final SurfaceHolder holder) {
running = true;
while(running){
handler.postDelayed(new Runnable() {
public void run() {
Canvas canvas = getHolder().lockCanvas();
if(canvas != null){
synchronized (getHolder()) {
doDraw(canvas);
}
holder.unlockCanvasAndPost(canvas);
}
}
}, 33);
}
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {}
}
Ho usato per avere un thread separato che ha gestito il disegno, ma che ha causato problemi con le variabili aventi valori differenti tra le filettature. Quando ho eseguito questo programma, ottengo questo errore:
04-20 10:54:35.577 1925-1931/com.thatoneprogrammerkid.gameminimum I/art﹕ Thread[2,tid=1931,WaitingInMainSignalCatcherLoop,Thread*=0xae668400,peer=0x12c00080,"Signal Catcher"]: reacting to signal 3
04-20 10:54:35.577 1925-1931/com.thatoneprogrammerkid.gameminimum I/art﹕ [ 04-20 10:54:35.627 1925: 1931 W/art ]
qualcuno sa come risolvere questo problema anche io sto ottenendo lo stesso errore –
@AkshayShah Potrebbe anche essere possibile aver creato un ciclo infinito –