ANR in Canvas.native_drawBitmap

I recently received the same ANR reports. ANR occurs when an application tries to draw some bitmap images (when rendering a GridView with ImageViews as elements). I did a lot of debugging and now I can say that the hangs do not depend on the bitmap or on the place where it is drawn.

50% free heap, images no more than 400px ^ 2
Grid elements do not have any custom layout - just a simple ImageView.
Tested on HTC Desire (1 GHz processor), Hero, emulators, etc.
ANR continues forever , so it, like the infinite loop, works when drawing a bitmap.

What else can cause such a hang?

The report is as follows:

DALVIK THREADS: "main" prio=5 tid=1 NATIVE | group="main" sCount=1 dsCount=0 s=N obj=0x40020ba0 self=0xddd0 | sysTid=32366 nice=0 sched=0/0 cgrp=unknown handle=-1345025972 at android.graphics.Canvas.native_drawBitmap(Native Method) at android.graphics.Canvas.drawBitmap(Canvas.java:1045) at android.graphics.drawable.BitmapDrawable.draw(BitmapDrawable.java:323) at android.widget.ImageView.onDraw(ImageView.java:860) at android.view.View.draw(View.java:6740) at android.view.ViewGroup.drawChild(ViewGroup.java:1640) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367) at android.view.ViewGroup.drawChild(ViewGroup.java:1638) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367) at android.view.View.draw(View.java:6743) at android.widget.FrameLayout.draw(FrameLayout.java:352) at android.view.ViewGroup.drawChild(ViewGroup.java:1640) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367) at android.view.View.draw(View.java:6743) at android.widget.FrameLayout.draw(FrameLayout.java:352) at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:1847) at android.view.ViewRoot.draw(ViewRoot.java:1407) at android.view.ViewRoot.performTraversals(ViewRoot.java:1163) at android.view.ViewRoot.handleMessage(ViewRoot.java:1727) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:123) at android.app.ActivityThread.main(ActivityThread.java:4627) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:521) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:878) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:636) at dalvik.system.NativeStart.main(Native Method) 
+4
source share
1 answer

It is very difficult to identify your problem without your code or at least a small sample. You probably need to upload images using AsyncTask . Also, enabling StrictMode is very useful for finding ANR errors.

 public void onCreate() { if (DEVELOPER_MODE) { StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder() .detectDiskReads() .detectDiskWrites() .detectNetwork() // or .detectAll() for all detectable problems .penaltyLog() .build()); StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder() .detectLeakedSqlLiteObjects() .detectLeakedClosableObjects() .penaltyLog() .penaltyDeath() .build()); } super.onCreate(); } 

Be sure to remove StrictMode before release. This will test VerifyError devices to level 9 api level. This is a good feature to use during development. This will cause your application to crash briefly when you do something that could block the UI thread.

+1
source

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


All Articles