Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TC-4078]: make ListSection methods run on UI thread as required #5658

Merged
merged 2 commits into from May 21, 2014

Conversation

mokesmokes
Copy link
Contributor

Prior to this fix I was seeing an occasional error message in my app: java.lang.IllegalStateException: "The content of the adapter has changed but ListView did not receive a notification. Make sure the content of your adapter is not modified from a background thread, but only from the UI thread. [in ListView(-1, class android.widget.ListView) with Adapter(class android.widget.HeaderViewListAdapter)]

See line notes for the bugs fixed

@@ -135,9 +139,10 @@ public void setAdapter(TiBaseAdapter a) {

@Kroll.method @Kroll.setProperty
public void setHeaderView(TiViewProxy headerView) {
this.headerView = headerView;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bug. Here the headerView property can be set in any arbitrary thread, and only notifyDataChange ensured the UI thread prior to calling adapter.notifyDataSetChanged. This fix makes sure that that the property change and adapter.notifyDataSetChanged are both called in the same code block on the UI thread, as required by Android. Fixed this for headerView, headerTitle, footerView, footerTitle.

mokesmokes referenced this pull request in mokesmokes/titanium_mobile May 5, 2014
@mokesmokes
Copy link
Contributor Author

Appcelerator team - this PR fixes occasional app crashes, please review and accept. Thanks.

@hieupham007
Copy link
Contributor

Code reviewed. Looks good

if (TiApplication.isUIThread()) {
handleSetHeaderView(headerView);
} else {
TiMessenger.sendBlockingMainMessage(getMainHandler().obtainMessage(MSG_SET_HEADER_VIEW, headerView));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be TiMessenger.sendBlockingMainMessage(getMainHandler().obtainMessage(MSG_SET_HEADER_VIEW), headerView);

@hieupham007
Copy link
Contributor

Functionally tested. Looks good after a couple minor fixes mentioned above.

@mokesmokes
Copy link
Contributor Author

Thanks for catching that.... Fixed.

hieupham007 added a commit that referenced this pull request May 21, 2014
[TC-4078]: make ListSection methods run on UI thread as required
@hieupham007 hieupham007 merged commit ce64103 into tidev:master May 21, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants