Android TimePicker SetTitle UIThread Issues -
Android TimePicker SetTitle UIThread Issues -
i understand calledfromwrongthreadexception exception means, cannot comprehend how code have written isn't executing on uithread in situation.
in main activity create handler.
private final handler handler = new apphandler(this);
in oncreatedialog method of activity, using constructor suggested android examples of timepicker dialogues. since getting calledfromwrongthreadexception in way didn't understand , wasn't reproducible on devices or emulator, tried pass reference of activity in create dialogue constructor.
so code create dialog looks this.
@override protected dialog oncreatedialog(int id) { final calendar c = calendar.getinstance(); switch (id) { case time_dialog_id: homecoming new timepickerdialog(this, this, gethandler(), mtimesetlistener, c.get(calendar.hour_of_day), 0, false);
the first instance of "this" gets used context dialog, sec instance gets stored off activity.
the dialog android sample code have been attempting prepare threading problems i'm seeing.
then within of dialog having threading issues. utilize main activity , seek utilize handler execute settitle command runnable.
mainactivity.gethandler().post(new runnable() { public void run() { settitle(mdateformat.format(mcalendar.gettime())); } });
edit: changing code effort run on ui thread using method on main activity instead of handler produces same results.
mainactivity.runonuithread(new runnable() { public void run() { settitle(mdateformat.format(mcalendar.gettime())); } });
here's re-create of stacktrace:
android.view.viewroot$calledfromwrongthreadexception: original thread created view hierarchy can touch views. @ android.view.viewroot.checkthread(viewroot.java:3214) @ android.view.viewroot.invalidatechild(viewroot.java:681) @ android.view.viewroot.invalidatechildinparent(viewroot.java:707) @ android.view.viewgroup.invalidatechild(viewgroup.java:2511) @ android.view.view.invalidate(view.java:5418) @ android.widget.textview.checkforrelayout(textview.java:5750) @ android.widget.textview.settext(textview.java:2866) @ android.widget.textview.settext(textview.java:2727) @ android.widget.textview.settext(textview.java:2696) @ com.android.internal.app.alertcontroller.settitle(alertcontroller.java:222) @ android.app.alertdialog.settitle(alertdialog.java:100) @ com.testapp.timepickerdialog$1.run(timepickerdialog.java:159) @ android.os.handler.handlecallback(handler.java:587) @ android.os.handler.dispatchmessage(handler.java:92) @ android.os.looper.loop(looper.java:130) @ android.app.activitythread.main(activitythread.java:3691) @ java.lang.reflect.method.invokenative(native method) @ java.lang.reflect.method.invoke(method.java:507) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:907) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:665) @ dalvik.system.nativestart.main(native method
also note utilize same handler on app execute things on ui thread.
any suggestions on other approaches might seek or tips debug appreciated.
thanks!
use
runonuithread(new runnable() { @override public void run() { //ui codes }});
edit i think u should deal dialogclass innerclass mainactivity,then phone call runonuithread
hope may help you
android
Comments
Post a Comment