android - Async Task OnProgressUpdate CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views -


i using asynctask download database progressdialog shows progress on ui. of users receiving error:

calledfromwrongthreadexception: original thread created view hierarchy can touch views.

as understand it, should happen if trying update views off of ui thread. here error:

com...updateops.dbcreate.onprogressupdate(dbcreate.java:70) @ com...updateops.dbcreate.onprogressupdate(dbcreate.java:1)

and here code:

public class dbcreate extends asynctask<string, string, string>{  private static context mctx; private static progressdialog mdialog; public static amazonsimpledbclient msdbclient; public static amazons3client ms3client; private static int mappversion; private static boolean mcreate;   public dbcreate(context ctx, int versioncode, boolean create) {     mctx = ctx.getapplicationcontext();     mappversion = versioncode;     mdialog = new progressdialog(ctx);     mdialog.setprogressstyle(progressdialog.style_horizontal);     mdialog.setmessage("checking server access. please wait...");     mdialog.setcancelable(false);     mdialog.setmax(1);     mdialog.show();      mcreate = create;  }  protected void onprogressupdate(string... name) {     if (name[0].equals("item")) {         mdialog.incrementprogressby(1);     } else if (name[0].equals("setmax")) {         mdialog.setprogress(0);         mdialog.setmax(integer.parseint(name[1]));   <-- line 70 }}   @override protected string doinbackground(string... arg0) {     **do stuff**     publishprogress("setmax", ""+ 3); } 

it looks me following supposed in order avoid error. know why it's happening?

edit: should mention code works of time. receiving crash reports on developer console.

according onprogressupdate(progress...) invoked on ui thread after call publishprogress(progress...).

you should analyze whole log report check if there chance async task created on other thread.

and if cannot find root cause can use handler created on ui thread workaround.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -