firebase / firebase/quickstart-android

android firebase file upload in background service stopped when clear app from recents.

Open
#781 3 comments 0 reactions 0 assignees View on GitHub
api: storage type: bug
Dominant language
Kotlin
Stars
9.3k
Forks
7.4k
Avg merge
2d 19h
Merged PRs (30d)
8

Description

### Step 1: Are you in the right place?

* For issues or feature requests related to the code **android storage** file a Github issue.
*

### Step 2: Describe your environment

* Android device: _____Mi note5
* Android OS version: _____oreo
* Google Play Services version: _____
* Firebase/Play Services SDK version: _____

### Step 3: Describe the problem:
I have used your code for file upload in background service. It works fine when the app is running. but when the app is removed from recent apps or get killed then the uploading and notification stopped and remains as it is.

```java
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public class NotificationJobService extends JobService implements UploadFileToServer.UploadEventListener {
private JobStartedListner jobStartedListner;
ArrayList sourceFileList = new ArrayList();
UploadFileToServer uploadFileToServer;

@Override
public void onPreExecute() {

}

@Override
public void onComplete() {

}

@Override
public void onProgressUpdated(Integer progress, int totalSize, int currentFilePosition) {

}

public interface JobStartedListner {
public void onJobStarted();
}

public NotificationJobService() {
}

@Override
public boolean onStartJob(JobParameters jobParameters) {
Log.e("Job Params", jobParameters.toString());
String[] data = jobParameters.getExtras().getStringArray("data");
for (int i = 0; i < data.length; i++) {
if (data[i] != null) {
File f = new File(data[i]);
sourceFileList.add(new File(data[i]));
}
}
uploadFiles(this, sourceFileList, this);
return false;
}

public void uploadFiles(UploadFileToServer.UploadEventListener uploadEventListener, ArrayList sourceFileList, Context context) {
uploadFileToServer = new UploadFileToServer(uploadEventListener, /*new File(imagepath)*/sourceFileList, context);
}

@Override
public boolean onStopJob(JobParameters jobParameters) {
uploadFileToServer.cancel(true);
return true;
}
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.