6

After connecting to the bluetooth, I need the child to send data out through that socket. But how do I get the socket over to the childActivity?

3
  • Why do you want to switch to another activity? And why do you send data on the UI Thread? Commented Mar 28, 2011 at 11:20
  • I have 2 different design of UI that need to send out data through the socket. Therefore I need to pass the socket over.
    – GJianHui
    Commented Mar 28, 2011 at 11:41
  • Or is there a way that I can call the write method in the main activity from the sub activity?
    – GJianHui
    Commented Mar 28, 2011 at 11:58

1 Answer 1

0

Not sure if it is the best design, but what I did here and it worked on my simple application was to have the bluetooth connection (the socket) as a "global variable", a variable of my main application (the class which extends the Application class).

In that way all my activities can get it and set it.

For doubts on how to set/get a global variable on such way, refer to Android global variable

Not the answer you're looking for? Browse other questions tagged or ask your own question.