How long is Android ViewTreeObserver alive? -


i working on app listens view events scrolling, layout drawn using viewtreeobserver. viewtreeobserver has method check if it's alive before doing eg. adding listeners.

i have reproduce issue of dead / not alive viewtreeobserver see if code works in production. don't see in android documentation reproduce it.

i appreciate / pointers.

thanks

in fact, if check source code of class viewtreeobserver, there "kill" function set malive false, here, but never invoked.

/**  * marks viewtreeobserver not alive. after invoking method, invoking  * other method {@link #isalive()} , {@link #kill()} throw exception.  *  * @hide  */ private void kill() {     malive = false; } 

in opinion, observer become unavailable (but not un-alive, couldn't use isalive() determine current observer's state) after:

  1. you removed listener(s), such view.getviewtreeobserver().removeongloballayoutlistener(this);

  2. the current activity containing view destroyed


Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -