Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This fetch instance has been closed. Create a new instance using the builder #659

Open
wahyurama-creator opened this issue Jun 26, 2023 · 4 comments

Comments

@wahyurama-creator
Copy link

When i resume my activity, error is showing "com.tonyodev.fetch2.exception.FetchException: This fetch instance has been closed. Create a new instance using the builder", how to fix it?

@Umesh-Patidar
Copy link

I am getting same crash. Could you please check this.

private fun downloadMedia(filePath: String) {
val fetchConfiguration = FetchConfiguration.Builder(this)
.setDownloadConcurrentLimit(5)
.setProgressReportingInterval(500)
.build()
Fetch.Impl.setDefaultInstanceConfiguration(fetchConfiguration)
fetch = Fetch.Impl.getDefaultInstance()
val mediaRequest = url?.let { Request(it, filePath) }
mediaRequest?.let { request->
request.priority = Priority.HIGH
request.networkType = NetworkType.ALL
// fetch = if (fetch == null || fetch?.isClosed == true) FoneAppApplication.instance.getFetch() else fetch
fetch?.enqueue(request, { updatedRequest: Request? ->
Timber.d("Media File enqueue successfully!! ${updatedRequest?.id}")
}) { error: Error? ->
Timber.d("Media File is not enqueue!! ${error?.name}")
}
}

com.tonyodev.fetch2.exception.FetchException: This fetch instance has been closed. Create a new instance using the builder.
com.tonyodev.fetch2.fetch.FetchImpl.throwExceptionIfClosed(FetchImpl.kt:1226)
com.tonyodev.fetch2.fetch.FetchImpl.enqueueRequest(FetchImpl.kt:97)
com.tonyodev.fetch2.fetch.FetchImpl.enqueue(FetchImpl.kt:69)

@tech-ajit-mob
Copy link

I think it's a serious issue. We are facing the same when we are trying to download back-to-back images.

@tech-ajit-mob
Copy link

is there any update?

@tonyofrancis
Copy link
Owner

Once a Fetch instance is closed It can no longer be used. When the activity is started check if fetch is closed by doing the following

 private Fetch fetch;
 
     @Override
    protected void onStart() {
        super.onStart();
        if (fetch == null || fetch.isClosed()) {
            //create new fetch instance
            final FetchConfiguration configuration = new FetchConfiguration.Builder(this).build();
            fetch = Fetch.Impl.getInstance(configuration);
        }
    }
    
        @Override
    protected void onDestroy() {
        super.onDestroy();
        if (fetch != null && !fetch.isClosed()) {
            fetch.close();
        }
        fetch = null;
    }
 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants