android - Device goes black and Launch timeout expires -


since new android programming, not sure how write code efficiently hence reason question. creating app. basic app in app generates 10 random math questions , evaluates left right (ignoring orders of operations). e.g. 3+5/2 should equal 4 instead of 5.5.

i getting error launch timeout has expired. have researched , found out because main thread doing work. how overcome this? app first alot randomizing integers, case?

this code. pretty long. p.s. in display method, hrdcoded display first elements see if display.

public void initanswers(string[] questiontobelooped){       for(int =0; < questiontobelooped.length; i++){            if(mathoperations.length == 2){             runningtotal = evaluateanswertwooperations(mathoperations[0], mathnumbersinintformat.get(0), mathnumbersinintformat.get(1));         }else{             int operationscounter =0;             int numberscounter =1;             runningtotal = mathnumbersinintformat.get(0);             while(mathoperations[operationscounter] != "="){                 runningtotal = evaluateanswertwooperations(mathoperations[0],runningtotal,mathnumbersinintformat.get(numberscounter));             }          }         answers[i] = runningtotal;     }  } 

could tell me how write efficiently , can provide tips generate fluent , efficient apps.

not sure in code cause, should offload heavy work asynctask. asynctask allow execute code in background thread via doinbackground , callback ui thread via onpostexecute. heavy work doing around looping constructs have.

keep in mind cannot modify ui background, if need update ui, wait until heavy work finished , in onpostexecute.

see docs here on asynctask.

also worth noting asynctask has lot of flaws, since new - recommend start.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -