Activity Idle Timeout for ActivityRecord

独自空忆成欢 提交于 2019-12-04 03:03:21
kcoppock

Oh geez. One of those things that's pretty hard to diagnose outside of trial and error, but I've figured it out. For reference, should anyone else have this problem, it came down to a custom view in my layout. I had added a ViewTreeObserver.OnGlobalLayoutListener() to do some layout modifications after the layout pass, but within that listener I modified the layout and thus caused another layout, essentially creating an infinite loop (but somehow not causing an ANR). My solution was like so:

private class BoardLayoutListener implements OnGlobalLayoutListener {
    @Override
    public void onGlobalLayout() {
        //...do stuff here

        //REMOVE this listener so that you don't repeat this forever
        ViewTreeObserver obs = SudokuBoard.this.getViewTreeObserver();
        obs.removeGlobalOnLayoutListener(this);
    }
}

This solution is quite ironic, considering my second highest rated answer on StackOverflow specifically deals with this. :P

sigh

I've had the same issue today but as it turned out to have a different cause and solution I decided to add the information here just in case it might help someone else.
In my case problem was caused because I had the following line inside my onActivityResult() method:
android.os.Debug.waitForDebugger();
I Just deleted the line and the problem was gone. This line is usually used to synchronize the debugger with the OS threads but I just figured it shouldn't be used anywhere. Oddly the problem would not appear until I had my phone disconnected from the desktop.

Regards

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!