[英]Retrieving custom Future Android Ion by Koush
是Android的新手。 抱歉,这个问题太简单了。 我已经尝试寻找解决方案已有数周了。 我在我的项目中使用https://github.com/koush/ion中的Ion。 上传和下载效果很好,但是在恢复应用后检索特定的自定义Future时,我陷入了困境。 我想检索一个操作,例如上载并停止它,而不会影响其他上载,反之亦然。
解决方案是在创建返回Future回调的流程的过程中实现广播接收器。 这将使您仅通过触发广播接收器即可取消/停止其操作
// set broadcast listeners
BroadcastReceiver broadcast = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String cancelled_msg_time = intent.getStringExtra("time");
// check if this download was cancelled
if (my_time.equals(cancelled_msg_time)) {
if (upload_started) {
// cancel asynctask
asycProcess.cancel(true);
}
// set flag as cancelled
cancelled = true;
}
}
};
// register the broadcast receiver to cancel downloads
IntentFilter intent_filter = new IntentFilter();
intent_filter.addAction("CANCEL_UPLOAD");
context.registerReceiver(broadcast, intent_filter);
然后,您的执行应以某种方式检查其状态,然后再继续操作
if (!cancelled) {
file_progress_handler = new FileProgressHandler();
// proceed with upload
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.