title: Android Firebase Storage Keep Uploading When Activity Is Destroyed
body: <p>When someone using my android app is uploading a video to Firebase Storage, I want the video to upload even when the activity is destroyed. I tried using asynctask, but it doesn't seem to work. Here is the asynctask code:</p>
  
  <pre><code>public class UploadAttachment extends AsyncTask&lt;Void, Void, Void&gt; {
  
      @Override
      protected Void doInBackground(Void... params) {
          userRef.child("currentSeason").addListenerForSingleValueEvent(new ValueEventListener() {
              @Override
              public void onDataChange(DataSnapshot dataSnapshot) {
  
                  if (dataSnapshot.exists()) {
  
                      final String attachCurrentSeason = dataSnapshot.getValue().toString();
  
                      seasonRef.child("id").addListenerForSingleValueEvent(new ValueEventListener() {
                          @Override
                          public void onDataChange(DataSnapshot dataSnapshot) {
  
                              String path = "users/" + mAuth.getUid() + "/" + attachCurrentSeason + "/game" + String.valueOf(Integer.parseInt(dataSnapshot.getValue().toString()) - 1);
                              StorageReference storageReference = storage.getReference(path);
  
                              storageReference.putBytes(byteArray);
  
                          }
  
                          @Override
                          public void onCancelled(DatabaseError databaseError) {
  
                          }
                      });
  
                  }
  
              }
  
              @Override
              public void onCancelled(DatabaseError databaseError) {
  
              }
          });
          return null;
      }
  }
  </code></pre>
  
  <p>I've read many things saying that Asynctask will still run when the activity is destroyed, but it doesn't work for me. Is it not allowed to use firebase in asynctask?</p>
  
  <p>Any help is appreciated. Thanks in advance!</p>