java - Recursive factorial function locking up android UI with AsyncTask implementation -


i have factorial function written in java android application. find when ever run locks ui. put in asynctask see if carry out function in background when execute code again still locks up.

by locks mean user interface freezes until calculation complete.

thanks :)

p.s. sorry if bad post.

code:

private class factorialtask extends asynctask<bigdecimal,bigdecimal,bigdecimal>{     @override     protected bigdecimal doinbackground(bigdecimal...arg0){         bigdecimal m = arg0[0];         bigdecimal n = arg0[1];         bigdecimal z = m;         if(n.equals(zero)){             z = one;         }         else if(!m.equals(n)){             bigdecimal p = (n.subtract(m)).divide(two,0, roundingmode.floor);             bigdecimal x = factorial(m, m.add(p));             bigdecimal add_y = one.add(m.add(p));             bigdecimal y = factorial(add_y, n);             z = evalfact(x, y);         }         return z;      }     @override     protected void onprogressupdate(bigdecimal...values){         super.onprogressupdate(values);     }     @override     protected void onpostexecute(bigdecimal result){         super.onpostexecute(result);         displaytext(result);     } }    public static bigdecimal 2 = new bigdecimal("2"); public static bigdecimal 1 = new bigdecimal("1"); public static bigdecimal 0 = new bigdecimal("0");  public static bigdecimal factorial(bigdecimal m , bigdecimal n){     bigdecimal z = m;     if(n.equals(zero)){         z = one;     }     else if(!m.equals(n)){         bigdecimal p = (n.subtract(m)).divide(two,0, roundingmode.floor);         bigdecimal x = factorial(m, m.add(p));         bigdecimal add_y = one.add(m.add(p));         bigdecimal y = factorial(add_y, n);         z = evalfact(x, y);     }     return z; } public static bigdecimal evalfact(bigdecimal x, bigdecimal y ){     return x.multiply(y); } 

if it's mobile environment, try tail recursion.. cause saves stack.


Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

Swift game error message -