I guess this is too basic and as far as i searched i could not find any related questions.
I have an activity where i create a socket is created. I have three more activities that will read/write to the same socket. But I have to get the socket inside each activity. As far as i searched, the ‘service’ were to be the best option, but when i read through it, I think it is more of a background processing of data rather than storing just the variable for later use. Can you please let me know how to go forward?
I have
classA : Socket creation.
classB : Write to the socket.
calssC : Read from the socket.
My initial idea was to create an obj of classA inside B and C but i think it will not work. Can someone help me here?
You can use Application class instead of creating instance of Activity class for sharing fields or behavior between different components or Activities,services of your own Application
See following tutorials for sharing data between different components using Application class:
http://www.helloandroid.com/tutorials/maintaining-global-application-state
http://www.xoriant.com/blog/mobile-application-development/android-application-class.html
http://www.intridea.com/blog/2011/5/24/how-to-use-application-object-of-android#