Search code examples
androidhtmlcsscordova

Android WebView renders blank/white, view doesn't update on css changes or HTML changes, animations are choppy


When ever I make a css class change, the changes don't always appear. This appears to happen when I have a touch event that adds something like a down class name to a button. The button doesn't update, and neither does anything else on the page. It's very inconstant in when it works. I've also noticed that sometimes my elements appear white with no content or anything. This is very frustrating!


Solution

  • I implemented kyle's solution and it solved the problem. Howewer I noticed a huge battery drain on android 4.0.4 when the app was open. Also after the change I had users complaining that the swiftKey keyboard was not working with my app anymore.

    Every change in my app are triggered by a user action so I came up with a modified version that only trigger invalidate() after a touchEvent:

        Handler handler = new Handler();
        public boolean onTouchEvent (MotionEvent event){
            super.onTouchEvent(event);
            handler.postDelayed(triggerInvalidate, 60);
                handler.postDelayed(triggerInvalidate, 300);
            return true;
        }
    
        private Runnable triggerInvalidate=new Runnable(){
            public void run(){
                invalidate();
            }
        };
    

    Never did any programming with Java so there might be a better solution to do this.