• Post Reply Bookmark Topic Watch Topic
  • New Topic

Bluetooth open problem : Connector.open() blocking..  RSS feed

Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I am developing an application in Motorola iDEN phones for connecting our barcode scanner to iDEN phones via Bluetooth.

My application is built over a custom SDK. The SDK has done all the underlying activities for open the connection with scanner, communication and close the connection. All the UI updates are done in application itself.

I am using the javax.microedition.io.Connector class for open the Bluetooth connection with scanner by calling the Connector.open()method. We are using a separate thread for handle this. If the scanner goes to sleep mode (Bluetooth) for saving the battery life, the connection with the scanner closes automatically. Our requirement is to reconnect to the same scanner, if the scanner wakes up from the sleep mode before the application exits. We are using a reconnection thread to handle this. Reconnection thread calling Connector.open() in a loop.

Our problem:

Connector.open() is a blocking call, and it is calling from a thread of SDK. If we exit from the application after scanner goes to sleep mode, the application exits successfully. We are killing the reconnection thread at the application exiting time but if the Connector.open() is already called , the thread is waiting for the reply of open() call. So after exiting from the application, if we wake up the scanner from sleep mode, the scanner will connect to the device without application. If we wait for the timeout of Connector.open() call (ie; 30-45 seconds) and wakes up the scanner after that , it will not reconnected automatically.

One method to avoid this situation is to wait the main thread (ie; application) for the completion of reconnection thread before exiting the application. But it will take 30-45 seconds to exit the application once we will press the exit button.

There is no close () methods found in Connector class so I need to wait for open() call before exiting from the thread. Is there a method to handle this problem?

Thanks in advance
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!