ServiceGenerator.create(FileDownloadService.class) ĭownloadService. Let's look at an example: FileDownloadService downloadService = This will return the complete request data. But the reason to include it is not so that you can reuse the call (hint: use clone()), it's that you can analyze the request that was made using call.request(). When debugging, the code skips over the enqueue callbacks. Repository calls the NetworkDatasource class which contains the Retrofit api call. Thus, if the request was successful or even if it failed, you still can access the original Call object. I'm trying to use enqueue method inside a non-activity class using repository pattern. Analyzing Requests With the Call ObjectĪs you've already seen, Retrofit 2 includes the Call instance to every callback method. This can be very useful if you need to send the same request multiple times. You cannot simply use the same object and call execute() or enqueue() again: FileDownloadService downloadService = ServiceGenerator.create(FileDownloadService.class) Ĭall originalCall = downloadService.downloadFileWithDynamicUrlSync(fileUrl) Ĭallback downloadCallback = new Callback() One of the first things you've to know about the Call class and its instances: each instance is special made for one and only one request. All the features we'll show you apply for all Retrofit requests. What kind of request it is, doesn't really matter. If you're interested in the details, give it a quick read. In this blog post, we'll make use of the code from our how to download files blog post.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |