I am having trouble with a custom view displaying properly. When the view is first loaded (meaning the app is not cached in memory), the view displays OK. However, when the app is closed with the back button and then reloaded, the view is a black screen and does not display as intended. The view looks something like as follows. Basically, what happens is the constructor starts a timer which only stops when the view functions getHeight() and getWidth() are non- zero. The actual values for the screen height and width are needed by the draw function. What can I do to get the following view to draw when the app is reloaded.
public class CustomView extends View { private volatile boolean initializationDone = false; private Timer initializationTimer; public CustomView(Context context) { super(context); initializationDone = false; // do some other stuff here initializationTimer = new Timer(); initializationTimer.scheduleAtFixedRate(new InitializationHelper(), 50, 50); } private class InitializationHelper extends TimerTask { private volatile boolean timerCancelled = false; public void run() { if ((CustomView.this.getHeight() > 0) && (CustomView.this.getWidth() > 0)) { if (!timerCancelled) { timerCancelled = true; if (initializationTimer != null) { initializationTimer.cancel(); initializationTimer.purge(); } // do some more initialization here initializationDone = true; } postInvalidate(); } } } @Override public void onDraw(Canvas canvas) { super.onDraw(canvas); if (!initializationDone) { return; } // draw stuff here } } I have tried replacing the timer with the following, I still do not see the view display after starting the app again just after being closed. (It does display properly when the app is loaded fresh into memory with the following). @Override protected void onSizeChanged (int w, int h, int oldw, int oldh) { if ((w <= 0) || (h <= 0)) return; initializationDone = true; postInvalidate(); } Any ideas? -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en