如何修复应用程序不响应? [英] how to fix Application not responding?

查看:98
本文介绍了如何修复应用程序不响应?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经准备好paint应用程序,我的应用程序包含一个paint的自定义视图.当我们在自定义视图中绘制任何东西时,只需收集绘制的像素并将其存储在数组列表中,首先它可以正常工作(但要花很多时间),第二次 " 活动MyAlphabets(在应用程序MyAlphabets中)没有响应(强制关闭并等待).

i have prepared paint application,my application contains one custom view for paint.when we draw any thing in custom view just collect the drawn pixels and store in array list,first it's working fine(but it's taking lot of time) and second time " Activity MyAlphabets(in application MyAlphabets)is not responding(force close and wait)".

我的代码是

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时,

when we click on "force close" Logcat is,

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

这是在绘制时收集彩色像素的正确方法.请帮助我.

This is correct way to collect color pixels at the time of draw.Please help me..

如何解决此问题.请帮助我.

how to solve this problem. please help me..

推荐答案

由于您正在执行所有计算,包括在UI线程(onDraw)中进行分配,因此您的应用程序必然会出现应用程序无响应"错误.

Your application is bound to get "Application not responding" errors since you're doing all your computation, including allocation in the UI thread (onDraw).

首先,您应该尝试将计算移入非ui线程(请参见 AsyncTask ).任何耗时超过20毫秒的操作都必然会调用应用程序无响应"消息.

Firstly, you should try moving the computations into a non-ui thread (see AsyncTask). Any operation that is taking more than 20ms is bound to invoke the "Application Not responding" message.

其次,您应该尝试重构您的代码,以使您不必在每次绘制时都执行计算.基本上,将图像渲染为屏幕外的位图,对其进行缓存,然后从onDraw中的缓存副本进行渲染.恐怕如何做"的范围超出了本次讨论的范围.

Secondly, you should try and refactor your code such that you do not have to perform the computation every time you have to draw. Basically render your image is an off screen bitmap, cache it and render it from the cached copy in onDraw. The scope of "how to", I'm afraid, is beyond the scope of this discussion.

这篇关于如何修复应用程序不响应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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