Android 应用程序中的 WaitingInMainSignalCatcherLoop 错误 [英] WaitingInMainSignalCatcherLoop Error in Android Application

查看:305
本文介绍了Android 应用程序中的 WaitingInMainSignalCatcherLoop 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 android 应用程序,它每 33 毫秒刷新一次屏幕,在一对坐标处显示一个矩形.这是自定义视图的代码:

I have an android application that refreshes the screen every 33 milliseconds, displaying a rectangle at a pair of coordinates. Here is the code for the custom view:

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) {}

}

我曾经有一个单独的线程来处理绘图,但这会导致线程之间具有不同值的变量出现问题.当我运行这个程序时,我收到这个错误:

I used to have a separate thread that handled the drawing, but that caused problems with variables having different values between the threads. When I run this program, I get this error:

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      ]

推荐答案

这不是错误,而是 VM 让您知道您的应用已发送信号 3 (SIGQUIT).最可能的原因是应用没有响应并且系统正在执行 ANR 处理——SIGQUIT 导致 VM 转储堆栈跟踪.

That's not an error, that's the VM letting you know that your app was sent a signal 3 (SIGQUIT). The most likely cause is that the app was unresponsive and the system is doing ANR processing -- SIGQUIT causes the VM to dump a stack trace.

您是否在 logcat 中看到 ANR 投诉?

Do you see ANR complaints in logcat?

查看您的代码,您在 surfaceCreated() 中循环,它在 UI 线程上运行.这意味着您的应用程序将无法处理来自系统的消息(或绘制视图,或接收用户输入).您可以像以前一样使用单独的线程(但具有更好的同步性),或者只是从 surfaceCreated() 中删除循环,然后让您的绘制处理程序重新发出 postDelayed() 每次执行时.

Looking at your code, you're looping in surfaceCreated(), which runs on the UI thread. That means your app won't be able to process messages from the system (or draw on Views, or receive user input). You can either use a separate thread as you did before (but with better synchronization), or just remove the loop from surfaceCreated() and then have your draw handler re-issue postDelayed() every time it executes.

这篇关于Android 应用程序中的 WaitingInMainSignalCatcherLoop 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆