1

While on most of the devices my app is working fine, on some devices (LG G3, Samsung Galaxy S6 so far) I have experienced a strange error, I can not really unfold:

Setting tileMode (either via XML or programmatically) to anything (clamp/repeat/mirror) on a BitmapDrawable, that is the backround of a layout, makes that background completely black-, and the app restart after ~20 seconds - without any sign of anything going wrong (no messages in LogCat, none of these callbacks of my activity is called: onPause(), onStop(), onDestroy()).

As there were some inconsistency among these freezes/crashes depending on the Bitmap being used, I started playing around with the .png images, and figured out, that I can get rid of (most of) these crashes, if I reduce the size of these images (<200x200).

Since

  • there are still some crashes and

  • I can not be sure about that size threshold for all the devices

I am still looking for a general solution, maybe some of you can help me with.

meztelentsiga
  • 171
  • 1
  • 10
  • and for those bigger pngs (>200x200) what happens if you use no `tileMode`? – pskink Aug 31 '16 at 05:06
  • Then everything is fine, except that the image is stretched to the size of the layout. – meztelentsiga Aug 31 '16 at 09:25
  • use `android:gravity` then – pskink Aug 31 '16 at 09:28
  • I did not mention, but I use repetitive images, so I would cover the whole background with a smaller image that is repeated in both directions, not changing the size of the layout. I think `android:gravity` is not suitable for this. So I do need setting `tileMode`. – meztelentsiga Aug 31 '16 at 09:59
  • so if std `BitmapDrawable` is not working for you use for testing `ShapeDrawable` with a custom `ShapeDrawable.ShaderFactory` – pskink Aug 31 '16 at 10:04

1 Answers1

1

Although this thread was not exactly about the same problem I had, it helped me accidentally. Setting the layerType of the layout in question to software like

  • android:layerType="software", or

  • view.setLayerType(View.LAYER_TYPE_SOFTWARE, null);

made the black backgrounds and the app restarts disappear.

It turned out also, that making the background images smaller didn't solve the problem, it only made it appear less often.

Thanks for the help pskink anyway!

Community
  • 1
  • 1
meztelentsiga
  • 171
  • 1
  • 10
  • I love you *so much* right now. I have spent the past 5 days, 4+ hours each day, trying to diagnose and solve this issue. I was about to just quit android development for good (no joke). My chest quite literally exploded in excitement as I read your OP - it was *exactly* the same issue I was having, and `android:layerType="software"` has, as far as I can tell, completely solved the issue. [Link to my issue](http://stackoverflow.com/questions/39585642/android-seemingly-harmless-layout-causes-app-to-crash-after-short-use-without). I just wanted to let you know how helpful this was for me. – Whelch Sep 22 '16 at 03:11
  • I know exactly what you are talking about! :D Had the same effort solving this and almost quit as well ;) – meztelentsiga Sep 22 '16 at 10:57