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

未关闭
#781 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
25/100
Issue 类型
缺陷
描述清晰度
需要澄清
活跃度
停滞
技术栈
android, firebase, java
领域
mobile

调研方向

从 issue 中的 NotificationJobService 示例开始,重点查看 onStartJob 和 onStopJob,并追踪当应用从最近使用的应用中移除时 UploadFileToServer 是如何创建和取消的。payload 没有指定 repository 文件或测试;完成的标准是,应用从最近使用的应用中移除后,后台上传及其通知仍会继续,或以可见的方式失败。

由索引模型根据 Issue 内容生成。

描述

api: storage type: bug
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.

@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public class NotificationJobService extends JobService implements UploadFileToServer.UploadEventListener {
    private JobStartedListner jobStartedListner;
    ArrayList<File> sourceFileList = new ArrayList<File>();
    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<File> sourceFileList, Context context) {
        uploadFileToServer = new UploadFileToServer(uploadEventListener, /*new File(imagepath)*/sourceFileList, context);
    }

    @Override
    public boolean onStopJob(JobParameters jobParameters) {
        uploadFileToServer.cancel(true);
        return true;
    }
}
主要语言
Kotlin
星标
9.3k
派生
7.4k
平均合并
7 天 9 小时
30 天内合并 PR
6

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

firebase/quickstart-android 的其他 Issue

查看 firebase/quickstart-android 的全部 Issue

相似的 Issue

更多 Kotlin Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。