notifications - android.view.ViewRoot$CalledFromWrongThreadException in badge view -
i create app notify count server, service part working fine. in count showed in badge view fine. when click badgeview time have issue followed
logcat
04-09 10:46:11.741: w/system.err(321): android.view.viewroot$calledfromwrongthreadexception: original thread created view hierarchy can touch views. 04-09 10:46:11.751: w/system.err(321): @ android.view.viewroot.checkthread(viewroot.java:2932) 04-09 10:46:11.760: w/system.err(321): @ android.view.viewroot.requestlayout(viewroot.java:629) 04-09 10:46:11.760: w/system.err(321): @ android.view.view.requestlayout(view.java:8267) 04-09 10:46:11.861: w/system.err(321): @ android.view.view.requestlayout(view.java:8267) 04-09 10:46:11.861: w/system.err(321): @ android.view.view.requestlayout(view.java:8267) 04-09 10:46:11.861: w/system.err(321): @ android.view.view.requestlayout(view.java:8267) 04-09 10:46:11.880: w/system.err(321): @ android.view.view.requestlayout(view.java:8267) 04-09 10:46:11.880: w/system.err(321): @ android.view.view.requestlayout(view.java:8267) 04-09 10:46:11.930: w/system.err(321): @ android.view.view.requestlayout(view.java:8267) 04-09 10:46:11.930: w/system.err(321): @ android.view.view.requestlayout(view.java:8267) 04-09 10:46:11.941: w/system.err(321): @ android.view.view.requestlayout(view.java:8267) 04-09 10:46:11.941: w/system.err(321): @ android.view.view.requestlayout(view.java:8267) 04-09 10:46:11.941: w/system.err(321): @ android.view.view.requestlayout(view.java:8267) 04-09 10:46:11.981: w/system.err(321): @ android.view.view.requestlayout(view.java:8267) 04-09 10:46:11.981: w/system.err(321): @ android.view.view.setflags(view.java:4641) 04-09 10:46:11.981: w/system.err(321): @ android.view.view.setvisibility(view.java:3116) 04-09 10:46:11.981: w/system.err(321): @ com.appname.badgeview.hide(badgeview.java:278) 04-09 10:46:11.981: w/system.err(321): @ com.appname.badgeview.hide(badgeview.java:221) 04-09 10:46:11.981: w/system.err(321): @ com.appname.mainactivity$9.run(mainactivity.java:253) 04-09 10:46:11.981: w/system.err(321): @ java.lang.thread.run(thread.java:1019)
code
new thread(new runnable() { @override public void run() { if (shareduname != null) { while (true) { if (sharedpreferences.getint( kp.notification.get_notify_oldcount, 0) != 0) { try { thread.sleep(2000); int check = 0; final int ncount = sharedpreferences .getint(kp.notification.get_notify_count, 0); if (ncount != check) { runonuithread(new runnable() { public void run() {// access displaycount(ncount); } }); } else { notifiycount.hide(true); } } catch (exception e) { e.printstacktrace(); } } } } } }).start(); private void displaycount(int count) { try { if (shareduname != null) { if (!check == true) { notifiycount.hide(true); } notifiycount = new badgeview(this, imgnotification); notifiycount.settext(string.valueof(count)); notifiycount.setbadgeposition(badgeview.focus_left); notifiycount.toggle(); check = false; } else { notifiycount.hide(); } } catch (exception e) { e.printstacktrace(); } }
where ever making ui changes other thread try use
mactivity.runonuithread(new runnable() { public void run() { } });
i think made ui changes in notifiycount.hide(true); || try activity instance in oncreate() method.
Comments
Post a Comment