在这里,我尝试从Firebase存储中的Adapter(recyclerview)上载数据,并尝试在Firebase实时数据库中成功放置任务放置数据(例如ex:url),并在sqlite离线数据库中进行更改。 这是我的适配器onbindviewholder的代码
Uri sendingImageURI=Uri.fromFile(new File(messages.getImagepath()));
final Uri sendingThumbURI=Uri.fromFile(new File(messages.getThumbpath()));
//This is a uploading image task which i want to keep continue after pause, destroy of activity even kill app//
filepath.putFile(sendingImageURI).addOnCompleteListener(new OnCompleteListener<UploadTask.TaskSnapshot>() {
@Override
public void onComplete(@NonNull Task<UploadTask.TaskSnapshot> task)
{
if(task.isSuccessful()) {
filepath.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
@Override
public void onSuccess(Uri uri) {
messageFromAdapter.setImageurl(String.valueOf(uri));
rootRef.child("Messages").child(messages.getFromid()).child(ReceiverID).child(messages.getPushkey()).setValue(messageFromAdapter, new DatabaseReference.CompletionListener() {
@Override
public void onComplete(@Nullable DatabaseError databaseError, @NonNull DatabaseReference databaseReference) {
notifyDataSetChanged();
}
});
}
});
}
}
在这里我要实现上传任务,继续在
中运行排序
if(uploading task is start)
{
keep running in background until finish or exception
}
答案 0 :(得分:2)
您可以在您的应用中实现服务,服务用于在后台运行,例如下载,上传内容