Waiting for X time in loop using JAVA/Android -
in code want check longitude , latitude value. if values empty, code check 15 seconds. if values received , while loop break , show "you win". if still empty, should show "error in gps" after 15 seconds. problem code waiting progress bar not showing in screen because screen got stuck during wait time. after 15 seconds screen free. please tell me how resolve issue.
@override public void onclick(view arg0) { // todo auto-generated method stub toast.maketext(getbasecontext(), longitude.gettext(), toast.length_long).show(); toast.maketext(getbasecontext(), latitude.gettext(), toast.length_long).show(); pbar = new progressdialog(oproprietor.this); pbar.setcanceledontouchoutside(false); pbar.setprogressstyle(progressdialog.style_spinner); pbar.setmessage("waiting 15 seconds"); pbar.show(); long t= system.currenttimemillis(); long end = t+15000; while(system.currenttimemillis() < end) { if(!longitude.gettext().equals("") || !latitude.gettext().equals("") ){ pbar.dismiss(); break; } else continue; } if(longitude.gettext().equals("") || latitude.gettext().equals("")){ pbar.dismiss(); toast.maketext(oproprietor.this, "error in gps", toast.length_long).show(); } else if(!longitude.gettext().equals("") || !latitude.gettext().equals("") ){ pbar.dismiss(); toast.maketext(oproprietor.this, "you win", toast.length_long).show(); } } });
since android, recommend using asynctask
on thread. this question has relevant details on how safely. using java thread/runnable
introduces ui issues in android when interacting ui thread external thread.
Comments
Post a Comment