Monday 15 March 2010

android - Handle with AlertDialog into the AsyncTask -



android - Handle with AlertDialog into the AsyncTask -

i trying phone call alertdialog asynctask. wrote code , works, when take item in alertdialog alertdialog freezes foreground ui working. help me please write right code task or help me please prepare freeze alertdialog after choosing item. trying phone call dismiss() method before uihandler.getlooper.suit() line, nil changed.

@override protected void doinbackground(void... arg0) { looper.prepare(); final handler uihandler = new handler(); uihandler.post(new runnable() { public void run() { alertdialog.builder chooser = new alertdialog.builder(ctx); facultychooser.settitle("choose") .setcancelable(false) .setitems(faculties, new dialoginterface.onclicklistener() { @override public void onclick(dialoginterface dialog, int item) { uihandler.getlooper().quit(); } }) .create() .show(); } }); looper.loop(); }

ps: it's not total code easier reading.

i think error occurred because seek run handler (ui thread) in doinbackground (background thread). solution create sure alert dialog created in ui thread.

move code :

alertdialog.builder chooser = new alertdialog.builder(ctx); facultychooser.settitle("choose") .setcancelable(false) .setitems(faculties, new dialoginterface.onclicklistener() { @override public void onclick(dialoginterface dialog, int item) { uihandler.getlooper().quit(); } }) .create() .show();

to onpostexecute or onpreexecute create sure dialog created on ui thread.

and delete final handler uihandler = new handler(); because onpostexecute/onpreexecute running on ui thread.

android android-asynctask handler android-alertdialog

No comments:

Post a Comment