如何修复应用程序没有响应?

问题描述 投票:4回答:1

我准备了涂料应用程序,我的应用程序包含一个自定义视图的paint.when我们在自定义视图中绘制任何东西只收集绘制的像素并存储在数组列表中,首先它工作正常(但它花了很多时间)和第二次“ Activity MyAlphabets(在应用程序MyAlphabets中)没有响应(强制关闭并等待)“。

我的代码是,

public void onDraw(Canvas canvas) {

        if (myDrawBitmap == null) {
            myDrawBitmap = Bitmap.createBitmap(canvas.getWidth(),
                    canvas.getHeight(), Bitmap.Config.ARGB_8888);
            bmpDrawCanvas = new Canvas(myDrawBitmap);
            intDrawArray = new int[myDrawBitmap.getWidth()
                    * myDrawBitmap.getHeight()];
        }
        if (bmpDrawCanvas != null) {
            for (Path path : MyActivity.mArryLstPath) {
                bmpDrawCanvas.drawPath(MyActivity.mPath,
                        mPaintAlphabet);
            }
myDrawBitmap.getPixels(intDrawArray, 0, 220, 0, 0, 220, 305);
                   for (int i = 0; i < intDrawArray.length; i ++) {

                if (intDrawArray[i] == 0xFFFFFFFF) {

                    if (MyActivity.mArryLstDrawnPixels.contains(i)) {

                    } else {
                        MyActivity.mArryLstDrawnPixels.add(i);
                    }
                }
}

当我们点击“强制关闭”时Logcat是,

INFO/ActivityManager(52): Killing process com.qteq.myapplication (pid=225) at user's request

 INFO/Process(52): Sending signal. PID: 225 SIG: 9

 INFO/ActivityManager(52): Process com.qteq.myapplication (pid 225) has died.

 INFO/WindowManager(52): WIN DEATH: Window{608fbd10 com.qtq.myapplication/com.qtq.myapplication.MyApplicationActivity paused=false}

 INFO/UsageStats(52): Unexpected resume of com.android.launcher while already resumed in com.qtq.myapplication
 ERROR/gralloc(52): [unregister] handle 0x4a2740 still locked (state=40000001)

 WARN/InputManagerService(52): Got RemoteException sending setActive(false) notification to pid 225 uid 10025

这是在抽奖时收集彩色像素的正确方法。请帮帮我..

如何解决这个问题呢。请帮我..

android android-canvas android-custom-view
1个回答
7
投票

您的应用程序必然会因为您正在进行所有计算而获得“应用程序无响应”错误,包括在UI线程(onDraw)中进行分配。

首先,您应该尝试将计算移动到非ui线程中(请参阅AsyncTask)。任何超过20毫秒的操作都必须调用“应用程序未响应”消息。

其次,您应该尝试重构代码,这样您每次必须绘制时都不必执行计算。基本上渲染你的图像是一个屏幕外的位图,缓存它并从onDraw中的缓存副本渲染它。我担心,“如何”的范围超出了本次讨论的范围。

© www.soinside.com 2019 - 2024. All rights reserved.