简体   繁体   中英

How to keep continue uploading task even when activity and application destroyed?

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

  • activity goes to pause state.
  • activity destroyed
  • totally exit of app even when swiped app from recent item

In sort

if(uploading task is start)
{
keep running in background until finish or exception  
}

您可以在自己的应用中实施服务,服务用于在后台运行,例如下载,上传内容

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM