android - progress dialog in main activity's onCreate not shown -
after splash screen, takes 6 sec load oncreate contents in main activity. want show progress dialog while loading , here's did:
import ... private progressdialog mainprogress; public void oncreate(bundle davedinstancestate){ super.oncreate(savedinstancestate); setcontentview(r.layout.main); mprogress = new progressdialog (main.this); mprogress.setprogressstyle(progressdialog.style_horizontal); mprogress.setmessage("loading... please wait"); mprogress.setindeterminate(false); mprogress.setmax(100); mprogress.setprogress(0); mprogress.show(); ---some code--- mprogress.setprogress(50); ---some code--- mprogress.setprogress(100); mprogress.dismiss(); } and doesn't work... screen stays black 5-6 sec , load main layout. dont know part did wrong :*(
you need start busy code in other thread (than ui thread).
in activity create progressdialog , close in thread
mprogress = new progressdialog (main.this); runnable runnable = new runnable() { @override public void run() { // code needs 6 seconds execution // after finishing, close progress bar mprogress.dismiss(); } }; new thread(runnable).start();
Comments
Post a Comment