Android: View.isAttachedToWindow() is not in sync with actual state

100 Views Asked by At
View new_overlay = new View(this);
wm.addView(new_overlay, params);
new_overlay.isAttachedToWindow(); //false here

I expected isAttachedToWindow() to be true after addView(). I haven't found documentation indicating that addView() is asynchronous.

Adding a sleep of several seconds before checking isAttachedToWindow() does not result in it returning true. Eventually it does return true in my code but I haven't found what causes that to happen, and it does not depend on how much time passes between the add and query.

Is this expected or should isAttachedToWindow() return true immediately? (Android API 33, galaxy s23)

0

There are 0 best solutions below