Is it possible to use AWS Android TransferUtility in Service?

半世苍凉 提交于 2019-12-06 10:45:53

Yes it's possible to start a service from another service.

TransferUtility may fail to work if its Amazon S3 client gets garbage collected before TransferService gets it. Normally an object is passed as a parcelable in an intent between components. However it's quite complicated to make S3 client parcelable. So the SDK takes an alternate route by passing a weak reference of it stored in a static map. The key is that the caller must keeps the S3 client alive before TransferService gets it.

See https://github.com/aws/aws-sdk-android/issues/86 for more information.

Yes, its possible. But there are some steps you need to follow to make it work. You can also add the TransferListener to your TransferUtiltiy object and use that show notification and upload progress.

  1. Use Service instead of IntentService, because when you use TransferUtility.upload... the intent service does not wait for its completion etc and finishes instantly. So use Service class and write the uploading logic in onStartCommand method.

  2. TransferUtility uses a Service named "TransferService". So running this service via TransferUtility from your service you need to put your service and the AWS TransferService in the same process in the manifest like.

    <service
        android:name="com.amazonaws.mobileconnectors.s3.transferutility.TransferService"
        android:enabled="true"
        android:process=":sync" />
    <service
        android:name=".services.UploadService"
        android:enabled="true"
        android:process=":sync" />
    

UplaodService will be your own service that uses the TransferUtility

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!