android - ProgressDialog in a separate thread -
i have procedure extracts data database , populates list. want display progress dialog box while query executed, visually appears after query executed. believe have run progressdialog in separate thread, followed few suggestions , not make work.
so in activity have
private void displayallproductlistview(string sqlstatement) { progressdialog dialog = progressdialog.show(myactivity.context, "loading", "please wait...", true); //.................. //.................. //execute sql query here dialog.dismiss(); } thanks
1.show process dialog in main thread
2.start new thread (such thread a) process heavy job
3.when done, use handler send message thread main thread, latter dismisses process dialog
code private processdialog pd;
private void startdialog() { pd = progressdialog.show(mainactivity.this, "title", "loading"); //start new thread process job new thread(new runnable() { @override public void run() { //heavy job here //send message main thread handler.sendemptymessage(0); } }).start(); } handler handler = new handler() { @override public void handlemessage(message msg) { pd.dismiss(); } };
Comments
Post a Comment