AsyncQueryHandler -->同步更新

    技术2022-05-20  26

     

    view plain copy to clipboard print ? class QueryHandler extends AsyncQueryHandler {             QueryHandler(ContentResolver res) {                 super(res);             }                          @Override             protected void onQueryComplete(int token, Object cookie, Cursor cursor) {                 mActivity.init(cursor);             }         }    

     

    AsyncQueryHandler--->当contentProvied发生变化时候同步更新显示就可以通过使用AsyncQueryHandler类来达到这一要求

    上面的代码--->onQueryComplete()--->就是当cursor更新完之后的

     

    view plain copy to clipboard print ? public void init(Cursor c) {                    mAdapter.changeCursor(c);          if (mQueryCursor == null) {              MusicUtils.displayDatabaseError(this);              setListAdapter(null);              mReScanHandler.sendEmptyMessageDelayed(01000);              return;          }          MusicUtils.hideDatabaseError(this);      }    

     

    如上面的当cursor变化后就把adpter中的新cursor给新的值

    作用:

    当查询大量数据的时候,为了不阻塞UI线程,而提供的一个AsyncQueryHandler extentd Handler

    相当于我们线程中开始的handler。sendmessage()-->处理我们的东东

    结束时候又handler.sendmessage()的作用一样。

    不用通过线程来处理查询中费时间的事情。通过这个就可以实现。


    最新回复(0)