Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat is the android UI thread stack size limit and how to overcome it?
    primarykey
    data
    text
    <p>I'm getting <strong>java.lang.StackOverflowErrors</strong> when my view hierarchy is being drawn:</p> <pre><code>at android.view.View.draw(View.java:6880) at android.view.ViewGroup.drawChild(ViewGroup.java:1646) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373) at android.view.View.draw(View.java:6883) at android.view.ViewGroup.drawChild(ViewGroup.java:1646) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373) ... </code></pre> <p><a href="https://stackoverflow.com/questions/2762924/java-lang-stackoverflow-error-suspected-too-many-views">Research</a> points to my view hierarchy being too deep for Android to handle. Indeed, using <strong>Hierarchy Viewer</strong>, I can see that my longest nesting is <strong>19</strong> views (!)</p> <p>My app looks somewhat like the Google Play store app (with swipe tabs). Every tab is a nested fragment inside a fragment view pager - using v4 support and HoloEverywhere. Obviously, this is why my hierarchy has gotten a bit crazy.</p> <p>My questions:</p> <ol> <li><p>What is the <em>real</em> stack size limit? I found no way to measure the stack size of the UI thread. Some rumors on the net say 8KB, but is there a way to measure this <em>accurately</em> on some sample devices?</p></li> <li><p>Does the stack size limit change with OS ver? The same hierarchy does <em>not</em> crash on an 4.0.3 device but does crash on a 2.3.3 device (identical hardware). Why is that?</p></li> <li><p>Is there any solution except optimizing the hierarchy manually? I found no way to increase the <em>ridiculously</em> small stack of the UI thread. Sorry, but 60-100 stack frame limit is a joke.</p></li> <li><p>Assuming there's no miracle solution on #3, any recommendations for where the core hierarchy optimization should be done?</p></li> <li><p>Crazy idea - I noticed that every view layer adds about 3 function calls (View.draw, ViewGroup.dispatchDraw, ViewGroup.drawChild). Maybe I can make my own ViewGroup implementation (custom layouts) that is less wasteful on stack during draw()?</p></li> </ol>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload