java - View on New Activity Not Updating On UI Thread -
sadly, code complicated post interstices. however, i'll best give sparse amount of code may contribute problem.
so have things running under surface pushing out broadcasts whenever things updated on database (it's interface monitor server (one not connected internet) on android.). have broadcast receivers listening these broadcasts , run runnable on handler whenever broadcast looking for.
i'm using fragment activity being called main activity. activity has variable number of fragments have variable number of "widgets". these widgets have own broadcast receivers, listening , responding mentioned above. so, each broadcast registered when view created , unregistered upon deletion, each broadcast receiver contains reference item.
the problem using same exact, working logic on main activity not work when open second activity. reason, view not update when request (such textview.settext("blah") display "blah" on main activity, display nothing on new activity). using print statements, have noted thinks updated, if call "textview.settext("blah")" , print "textview.gettext()" print out "blah" despite note showing on ui.
this code using call task within broadcastreceiver (note item weak reference item):
task = new myrunnable(); if (item.get().getview() == null) return; item.get().getview().post(task);
this code 1 of updating runnables (where param intent broadcast , context application context , nameoftextview name of text view.):
string arg = param.getstringextra(broadcast); if (arg == null) return; int id = context.getresources().getidentifier(nameoftextview, "id", context.getpackagename()); view view = item.get().getview(); if (id == 0 || view == null || !view.isshown()) return; textview v = (textview) view.findviewbyid(id); v.settext(arg);
i've been @ hours no luck. best guess that, reason or another, it's not referencing correct widget. however, doesn't seem each broadcast created widgets, meaning things reference passes in should valid.
thank in advance help!
update
after great suggestion @mark herscher, have determined guess incorrect. view attempting change is, in fact, same view being displayed on ui. i've checked, triple checked, found issue , fixed issue threads running twice, , still ui not update correctly.
again, seems not occur using same broadcasts , runnables on main activity. problem isolated other activities.
for asking, here few lines of code start other activity:
intent = new intent(mainactivity.this, globalsettingsactivity.class); i.putextra(request_code, global_settings); startactivityforresult(i, global_settings);
these activities extend super type utilizes same code generated.
i doubt have started asynctask in second activity. please make sure current activity not have started asynctask. if asynctask executing in background, please comment , test app again. let me know results.
Comments
Post a Comment