I currently have an app that requires connection to a server in multiple activities. I am currently trying to create a class that handles the connection between multiple activities and provides getters to get the output streams, I have looked at a service class but I do not need to keep the connection when the app is not running.
I am not entirely sure what i need to do to get an object to be globally accessed from multiple activities without having to be instantiated the object in each activity.
A Service is still the best idea. You just have to make it keep track of how many Applications are connected to it (in onBind/onStartCommand/onUnbind), and make it shutdown when it goes to zero.
What is a bit tricky is that Applications are not really closed in Android when they don’t have focus: you would have to decide if an Application unbinds from the Service on onPause or onStop.