N
N
Nikolai Kargin2018-01-17 01:46:05
Android
Nikolai Kargin, 2018-01-17 01:46:05

How to make a background connection (Socket.io) in Android?

Implemented a stick type service for background socket connection. Everything is beautiful, except for the fact that many optimizers cut it, and in MIUI shells, sticks are generally ignored if the user has not allowed autorun and has not pressed a bunch of buttons.
If this at least somehow works in versions before Oreo, then in 26 it generally throws out an exception. As I understand it, they covered them for such things.
The question is what to do? How to implement this background connection if their launchers want to kill, and from the eighth android and the OS itself.
Messenger type app with asymmetric encryption. I read that Google push notification delivery services have a lot of problems, and this spoils the whole concept.
Specifically, I’m interested in something like this pattern: I left the application, lives for a few more minutes, then once at some intervals (20-30 minutes) it connects and uploads new messages. Ideally, of course, the connection should live the entire "active" day of the user.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Varakosov, 2018-01-17
@kgnk

To keep the socket open, you need to keep the device awake. The device is quickly discharged - the user is indignant. Therefore, you will have to disconnect regularly. The approach is standard, the device wakes up, wakelock is captured (required with an indication of the period), after which you can do your own thing. It must be remembered that if you did not release the wakelock and the system fell asleep by timeout or the timeout was too long, then it may not be given further.
Another option is to rewrite the interaction with the server in C. There are no such restrictions on the execution of native code.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question