Reputation: 347
Here i tried to upload data from Adapter(recyclerview) in firebase storage and on success of task put data (for ex:url)in firebase realtime database and also change in sqlite offline database. Here is my code from adapter 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();
}
});
}
});
}
}
Here i want to implement uploading task keep running in
In sort
if(uploading task is start)
{
keep running in background until finish or exception
}
Upvotes: 0
Views: 320
Reputation: 110
You can implement Services in your App, Services are used to run on background, Like downloading, Uploading something
Upvotes: 2