Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
Posts: 224
Registered: ‎03-29-2012
My Device: 9900
My Carrier: Wind

Cannot Stop a background thread

Hey all, im using a bluetooth search to discover devices and then using the device.getFriendlyName(true); method to return the devices name. The issue, however, is that if a device is detected, but then moves out of range, when it tries to retrieve the friendly name, it cannot and it hangs/lags for quite some time before returning null. I was hoping to build in a timeout into this system but I am not sure how to stop the background thread running the device.getFriendlyName(true) method as it hangs at that line and doesnt loop so I couldn't use a looped boolean, any thoughts?

Developer
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: Cannot Stop a background thread

Have you tried to wrap getFriendlyName in try {} catch() block and catch InterruptedException? You could (probably) send an interrupt from the outside using yourBackgroundThread.interrupt().

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Developer
Posts: 224
Registered: ‎03-29-2012
My Device: 9900
My Carrier: Wind

Re: Cannot Stop a background thread

I'll try that next, i just hope im right in assuming that the hang of that line is the issue. Bluetooth resources are tough here.

Developer
Posts: 1,041
Registered: ‎07-16-2008
My Device: ಠ_ಠ

Re: Cannot Stop a background thread

You can't interrupt threads on BB, it does nothing. The best you can do is check the boolean and bail out when it returns.

Developer
Posts: 224
Registered: ‎03-29-2012
My Device: 9900
My Carrier: Wind

Re: Cannot Stop a background thread

that's a shame, are you sure? So there isn't a way to interrupt a background thread?

Highlighted
Developer
Posts: 709
Registered: ‎09-10-2009
My Device: 8520, 8900, 9000, 9300, 9650, 9700, 9780, 9800, 9810, 9900, 9930
My Carrier: Verizon

Re: Cannot Stop a background thread


vingilot wrote:

that's a shame, are you sure? So there isn't a way to interrupt a background thread?


Interrupting a background thread is a java thing. The problem is that a lot of those sysetm call gets down to native code and context is not in the java environment anymore. So no, you cannot interrupt them.