android - Activity freezes when I use dialog -


i have created dialog customized loading view, on activity created constructor method , show whenever want using these codes

dialog.show(); dialog.hide(); 

but problem when leave app on background , return after few minutes freezes.

i sure dialog problem because when remove there no such thing.

the dialog content framelayout containing 4 imageview fade in - fade out animation.

how can avoid problem?

here class file

public class gateloading extends dialog {  imageview a, b, d, c;  int switch = 0; int cycle = 0;  activity activity;  public gateloading(activity activity) {     super(activity);     this.activity = activity;     requestwindowfeature(window.feature_no_title);     setcontentview(r.layout.gate_loading);     getwindow().setbackgrounddrawable(new colordrawable(android.graphics.color.transparent));     setcanceledontouchoutside(false);     setcancelable(false);      = findviewbyid(r.id.gate_loading_a);     b = findviewbyid(r.id.gate_loading_b);     c = findviewbyid(r.id.gate_loading_c);     d = findviewbyid(r.id.gate_loading_d);      a.setvisibility(view.gone);     b.setvisibility(view.gone);     c.setvisibility(view.gone);     d.setvisibility(view.gone);      timer();  }  private void timer() {     final timer tm = new timer();     tm.scheduleatfixedrate(new timertask() {         @override         public void run() {             activity.runonuithread(new runnable() {                 @override                 public void run() {                     if (switch == 0) {                         if (cycle == 0)                             fadein(a);                         else if (cycle == 1)                             fadein(b);                         else if (cycle == 2)                             fadein(c);                         else if (cycle == 3) {                             fadein(d);                             tm.cancel();                             timer();                         }                     } else {                         if (cycle == 0)                             fadeout(a);                         else if (cycle == 1)                             fadeout(b);                         else if (cycle == 2)                             fadeout(c);                         else if (cycle == 3)                             fadeout(d);                     }                     cycle();                 }             });         }     }, 1000, 300); }  private void cycle() {     if (cycle == 3) {         cycle = 0;         if (switch == 0)             switch = 1;         else             switch = 0;     } else         cycle++; }  private void fadein(imageview iv) {     animation fadein = new alphaanimation(0, 1);     fadein.setduration(1000);      iv.setanimation(fadein);     iv.setvisibility(view.visible); }  private void fadeout(final imageview iv) {     animation fadeout = new alphaanimation(1, 0);     fadeout.setduration(1000);      iv.setanimation(fadeout);     iv.setvisibility(view.visible);      final timer tm = new timer();     tm.scheduleatfixedrate(new timertask() {         @override         public void run() {             activity.runonuithread(new runnable() {                 @override                 public void run() {                     iv.setvisibility(view.gone);                     tm.cancel();                 }             });         }     }, 1000, 1000);   }  } 


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -