Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it okay to Query the DownloadManager on the UI Thread?

The DownloadManager has a method query(). My question is if it's okay to call this method on the UI Thread, or if it should only be called from a background thread?

Can calling it ever cause an ANR?

like image 316
yydl Avatar asked Apr 03 '13 23:04

yydl


1 Answers

If one looks at the source of the query() method:

public Cursor query(Query query) {
  Cursor underlyingCursor = query.runQuery(mResolver, UNDERLYING_COLUMNS, mBaseUri);
  if (underlyingCursor == null) {
    return null;
  }
  return new CursorTranslator(underlyingCursor, mBaseUri);
}

... this could be break down to the question whether it is safe to access cursors in the UI thread. See Mark Murphy's excellent answer to this. Extract:

So query the DownloadManager in a background thread.

like image 62
saschoar Avatar answered Sep 28 '22 17:09

saschoar