My app needs to keep open a connection with a server. In the past I would basically run a thread inside a foreground service. Of course being in the foreground I never had any issue whatsoever. I never tried to start my thread inside an activity because I know that it would get killed as soon as the activity would be in the background and garbage collected. However by keeping a static reference to my activity prevents the garbage collector from cleaning them up, hence my ClientThread could potentially keep the connection open with the server for an indefinite amount of time? At least until the device is being used from the user (contrary to the service in the foreground that would still run even with the screen locked). It's not a great solution but at least I could avoid using a service since using it for just for a connection seems pretty pointless.
However by keeping a static reference to my activity prevents the garbage collector from cleaning them up, hence my ClientThread could potentially keep the connection open with the server for an indefinite amount of time?
Your leaked activity's thread would keep running until your process is terminated. That could occur within milliseconds after your UI moves to the background.
at least I could avoid using a service since using it for just for a connection seems pretty pointless.
The point is to keep your process alive, until the device kills you off anyway.