开发者

How not to notify cursor very often after URI data changes

开发者 https://www.devze.com 2023-02-08 14:20 出处:网络
I have very common situation: activity displays ListView with data from CursorAdapter (items from feed), and cursor is being notified by ContentProvider about changes in data by its URI.

I have very common situation: activity displays ListView with data from CursorAdapter (items from feed), and cursor is being notified by ContentProvider about changes in data by its URI.

The problem appears when very many items are inserted (thousands of items), so UI becomes unresponsive after notifications. So i need to set more coarse notifications.

My ideas are:

  1. Do开发者_高级运维 not notify, requery by myself, e.g. every 1 second
  2. Save notification time in ContentProvider, and notify if it is older than 1 sec.

Any common solutions of this situation?

Thanks.


You should probably handle the notifications and updating of the adapter in an AsyncTask to keep the UI responsive. Combined with correct use of bindView and newView, you'll probably find your UI is much more responsive. See Moving CursorAdapter cursor creation to background thread and Android CursorAdapters, ListViews and background threads for a little more information.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号