A
A
ArtemEfremov2022-02-01 14:51:49
Java
ArtemEfremov, 2022-02-01 14:51:49

How to do HTTP-LongPolling via JetPack Workers?

I've been struggling with this problem for a long time now. The outcome is this: on Chinese phones in the background, everything falls off, or duplication of workers begins (which is rare).

Doing some testing in workers without networking (for example, sending notifications to the user in the background every minute) - everything works great. As I start working with the network in workers - that's it, there is a blockage. It is unknown how this happens.

public class LongPoll extends Worker {
   public LongPoll(Context c, WorkerParameters p) {
    super(c, p);
   }
   public Result doWork() {
     try {
    // здесь выполняется ожидающий запрос
     } catch (Exception e) {}
   // после выполнения HTTP-запроса запускаю повторную задачу
    return Result.success();
   }
  }


I tried both unique tasks and tasks with tags, well, it does not work normally in the background. It is better not to offer Firebase as a replacement, we have already worked with it - a sad experience. Yes, and intermediaries do not want to have. Android positions Worker's as a good alternative to background and legacy services. Well, nothing has worked so far. Help me please.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question