DownloadManager or DownloadManager + IntentService

96 Views Asked by At

In the case of using DownloadManager system service; some people creating an IntentService and then inside the onHandleIntent method, they call DownloadManager.Request:

public class DownloadService extends IntentService {
...    

    @Override
    protected void onHandleIntent(@Nullable Intent intent) {
        DownloadManager.Request request = new DownloadManager.Request(uri);
        request.setAllowedNetworkTypes(...);
        request.setNotificationVisibility(...);
        ...
        ((DownloadManager) getSystemService(DOWNLOAD_SERVICE)).enqueue(request);
    }
...
}

And whenever they want to download a file, they call startService.

What is the benefit of that? Why we don't just use DownloadManger directly?! (without IntentService)

0

There are 0 best solutions below