multithreading - Android - ProgressDialogs and Threads -


i have progressdialog couldn't display love nor money. bit of research suggested needed put in thread.

so example

public void update(final int scheduleid, final context context) {     final handler progresshandler = new handler() {         public void handlemessage(message msg) {             x.dismiss();         }     };                  x = progressdialog.show(context, "scheduling...", "calculating , storing dates", true, false);             new thread() {         public void run() {             // nothing             boolean bresult = updatehistory(scheduleid, context);             log.i("here","finished here?");             if (bresult) {                   progresshandler.sendemptymessage(0);             }         }     }.start(); } 

but seems happen me, spinner disappears off screen , activity finishes, while updatehistory continues run in background.

if move call updatehistory below .start() (outside of thread), don't progress spinner displayed @ all.

what im missing?

all code in activity.

what can recommend, websites appear talk threads , i've tried doing them every way can, , say, either the thread run in background , spinner displayed second, or no spinner @ while function runs in foreground.

thanks simon

the preferred way asynctask, should able thread, this:

public class myactivity extends activity {     ...     private static final handler_message_success = 0;     private progressdialog x;     ...     private handler handler = new handler(){         @override         public void handlemessage(message msg) {             switch(msg.what){             case handler_message_success:                 x.dismiss();             default:                 log.w("handler","handlemessage / message type not recognised / msg.what = "+string.valueof(msg.what));             }         }     };     private void backgroundprocess(){         x = progressdialog.show(myactivity.this, "scheduling...", "calculating , storing dates", true, false);         thread backgroundthread = new thread() {             @override             public void run() {                 boolean bresult = updatehistory(scheduleid, myactivity.this);                 log.i("here","finished here?");                 if (bresult) {                       message msg = message.obtain();                     msg.what = handler_message_success;                     handler.sendmessage(msg);                 }             }         };         backgroundthread.start();     } } 

Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

sql server - python to mssql encoding problem -

windows - Python Service Installation - "Could not find PythonClass entry" -