How to fix the application is not responding?

I have a drawing application, my application contains one custom view for paint.When we do something in the user view, just collect the drawn pixels and save it in the list of arrays, first it works fine (but it takes a lot of time) and the second time "MyAlphabets activity (in MyAlphabets application) is not responding (force close and wait).

My code

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

when we click on β€œforce closing” Logcat,

 INFO/ActivityManager(52): Killing process com.qteq.myapplication (pid=225) at user 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 the right way to collect color pixels while painting. Please help me..

How to solve this problem. please help me..

+4
source share
1 answer

Your application will definitely get "Application not responding" errors, since you are doing all your calculations, including highlighting in the user interface stream ( onDraw ).

First, you should try to move the calculations to a non-ui stream (see AsyncTask ). Any operation that takes more than 20 ms is required to cause the message "Do not respond to the application."

Secondly, you should try and reorganize your code in such a way that you do not have to perform calculations every time you have to draw. Basically, your image is an off-screen bitmap, cache it and take it out of the cached copy in onDraw . The explanation of β€œhow,” I'm afraid, is beyond the scope of this discussion.

+7
source

Source: https://habr.com/ru/post/1387322/


All Articles