Can I request a DownloadManager in a user interface thread?

DownloadManager has a query () method. My question is, is it okay to call this method on the user interface thread, or if it needs to be called only from the background thread?

Could this cause ANR?

+6
source share
1 answer

If you look 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 may be due to the question of whether it is safe to access cursors in the user interface thread. See Mark Murphy for an excellent answer . Exposure:

So request the DownloadManager in the background thread.

+4
source

All Articles