android - Exception in AnimationUtils.loadAnimation() (sometimes) -


i getting null pointer exception in line given in code below. problem is, exception occurs randomly. many times works throws exception (say 5% of times). appreciated.

handler handler = new handler(); handler.postdelayed(new runnable() {     public void run() {         animation animation = animationutils.loadanimation(getactivity().getapplicationcontext(), r.anim.dialog_main_show_amination);  //exception in line         fabadddeliveryboy.startanimation(animation);         fabadddeliveryboy.setvisibility(view.visible);      } }, 500); 

the problem handler not tied fragment lifecycle. handler messages can fire after fragment detached activity, , getactivity() return null.

as quick fix, can put runnable in variable , clear handler in e.g. ondestroyview():

handler.removecallbacks(runnable); 

for more elegant solution, consider making delay part of animation itself.


Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -