I am creating an application in which I always need to connect through a TCP socket. My application is already working well in terms of connectivity, but when it goes to the background, the Android system ultimately kills the process. This makes it disconnect from the server.
I was looking for a way to always keep the application alive, but found nothing. Can someone tell me what would be the best way to do this so that my application does not close when it was in the background, or if it was forbidden, force it to restart if it is closed? I start with this and produce a headache: S
EDIT This is part of my code:
public int onStartCommand(Intent intent, int flags, int startId) { Toast.makeText(this, "service starting", Toast.LENGTH_SHORT).show(); new Thread(new Runnable() { public void run() { Playit(); } }).start(); return START_STICKY; }
At startup, the application seems to be frozen. I do not have much experience, so perhaps my mistake is simple, and I did not notice it.
source share