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

How to cancel the task when cut off network #3652

Open
zhujunhua2012 opened this issue Dec 26, 2024 · 1 comment
Open

How to cancel the task when cut off network #3652

zhujunhua2012 opened this issue Dec 26, 2024 · 1 comment
Labels
question General question s3 Issues with the AWS Android SDK for Simple Storage Service (S3).

Comments

@zhujunhua2012
Copy link

State your question
I want to treat TransferState.WAITING_FOR_NETWORK as a final state, like failed.

final TransferObserver observer = transferUtility.download(filePath, myOutfile);
observer.setTransferListener(new TransferListener() {
    @UiThread
    @Override
    public void onStateChanged(int id, TransferState transferState) {
        // it's on UI thread
        switch (transferState) {
            case WAITING:
            case IN_PROGRESS:
                break;
            case PAUSED:
            case RESUMED_WAITING:
                break;
            case WAITING_FOR_NETWORK:
		// I want to treat this state as a final state
                // after involes cancel, I will not receive CANCELED callback
		transferUtility.cancel(id);
                break;
            case COMPLETED:
            case CANCELED:
            case FAILED:
                break;
            default:
                break;
        }
    }

    @Override
    public void onProgressChanged(int id, long bytesCurrent, long bytesTotal) {
    }

    @Override
    public void onError(int id, Exception e) {
    }
});

In default, it will block when I turn off the internet, WAITING_FOR_NETWORK will be passed in onStateChanged.

But I want to treat this issue as a failed state. I tried like above, transferUtility.cancel(id) when the state becomes to WAITING_FOR_NETWORK, but I can't receive the next state 'CANCELED', anything wrong?

another question, when I turn on the internet, start a new task to download a new file, previous transferObserver will receive a onStateChanged, althoug I canceled it like above. What should I do to cancel the record and task? (and I dont need the previous tasks' callbacks)

thanks!

Environment(please complete the following information):

  • implementation "com.amazonaws:aws-android-sdk-core:2.73.0"

Device Information (please complete the following information):

  • Device: RedMi K50
  • Android Version: Android 13, API 33
@github-actions github-actions bot added pending-triage Issue is pending triage pending-maintainer-response Issue is pending response from an Amplify team member labels Dec 26, 2024
@edisooon edisooon added the question General question label Dec 26, 2024
@github-actions github-actions bot removed the pending-triage Issue is pending triage label Dec 26, 2024
@edisooon edisooon added the s3 Issues with the AWS Android SDK for Simple Storage Service (S3). label Dec 26, 2024
@edisooon
Copy link
Member

Hi @zhujunhua2012 , thank you for submitting this issue. One of our team members will take a look into this matter and provide with an answer here.

@github-actions github-actions bot removed the pending-maintainer-response Issue is pending response from an Amplify team member label Dec 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question General question s3 Issues with the AWS Android SDK for Simple Storage Service (S3).
Projects
None yet
Development

No branches or pull requests

2 participants