Android progress dialoge view not showing -
i have developed simple asynctask class takes handlers parameters , whilst sending handlersendemptymessage(0) in dobackground load progressdialoge loading view reason doesnt show until end of executing stuff thats inside handler object (in other words progressdialogue blinks @ end).
here asynctask:
package com.kc.util; import android.app.progressdialog; import android.content.context; import android.os.asynctask; import android.os.handler; import android.util.log; public class loaddialoge extends asynctask<handler, integer, void> { private progressdialog progressdialog; private string tag = "loaddialoge"; private context mcontext; @override protected void onpostexecute(void result) { // todo auto-generated method stub super.onpostexecute(result); progressdialog.dismiss(); } @override protected void onpreexecute() { // todo auto-generated method stub super.onpreexecute(); showwait(); } @override protected void doinbackground(handler... params) { // todo auto-generated method stub for(handler mhandler : params){ mhandler.sendemptymessage(0); log.d(tag, "handler sending message" ); } return null; } private void showwait() { log.d(tag, "showwait"); progressdialog = new progressdialog(mcontext); progressdialog.settitle("retrieving contact details"); progressdialog.setmessage("please wait..."); progressdialog.setprogressstyle(progressdialog.style_spinner); progressdialog.show(); log.d(tag, " "); } public void setmcontext(context mcontext) { this.mcontext = mcontext; } }
and here handler passed class activity:
private handler mhandler = new handler() { @override public void handlemessage(message msg) { // todo auto-generated method stub super.handlemessage(msg); log.d(tag, "handlemessage"); initialiseonitemclicklisteners(); initialiseonclicklisteners(); initialiselistviewadapters(); loaddatatodb(); initializetitles(); initialize(); } }; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.abstract_main_menu); loaddialoge load = new loaddialoge(); load.setmcontext(this); load.execute(mhandler); }
im trying create generic async load screen works across activity wants use instead of copying , pasting above loaddialogue asynctask across each activity(which doing before , worked fine).
not surprising "blinks" it? doinbackground()
nothing @ all... task complete instantly. try using sendemptymessagedelayed()
instead of sendemptymessage()
if want fake there's processing or waiting going on in background task.
Comments
Post a Comment