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

New Contributor
Posts: 3
Registered: ‎12-17-2011
My Device: Blackberry Torch 9860
My Carrier: T-Com

Bluetooth JSR82 / Threads

[ Edited ]



I have a problem with the following Code:

public class MyApp extends UiApplication

public static void main(String[] args)
MyApp app = new MyApp();

public MyApp()
if(System.getProperty("bluetooth.api.version") != null)
Dialog.alert("JSR 82 Bluetooth APIs not present");

private void initializeMode()
pushScreen(new ClientScreen());


public ClientScreen(int uuid)


try {

_local = LocalDevice.getLocalDevice();
_discoveryAgent = _local.getDiscoveryAgent();
} catch (BluetoothStateException e) {



I start like in the BluetoothJSR82Demo with pushing a new Screen onto the stack. In the constructor I want to initiate a bluetooth device discovery.


Now the problem only appears when Bluetooth is disabled on the device at the beginning. So the getLocalDevice() command causes a Pop-Up that bluetooth has to be enabled. When the user chooses "yes"  then it takes round about 1 minute to enable it. The debugger output is like this:


[66988.26] BT: EIR set
[66996.805] VM:+GC(f)w=11
[66997.4] VM:-GCt=76,b=1,r=0,g=f,w=11
[66997.43] VM:QUOT t=4
[66997.43] VM:+CR
[66997.445] VM:-CR t=2
[67010.97] JVM: bklt @67010968: timer
[67010.97] JVM: bklt[1] @67010968: usrIdle 23, usrTime 30, usrAct 1
[67010.97] JVM: bklt[1] @67010968: chkIdle 29, currTime 30
[67010.97] JVM: bklt @67010968: setTimer 7
[67017.96] JVM: bklt @67017960: timer
[67017.96] JVM: bklt[1] @67017960: usrIdle 30, usrTime 30, usrAct 1
[67017.96] JVM: bklt[1] @67017960: chkIdle 36, currTime 30
[67017.96] JVM: bklt[1] @67017960: enableBacklight 0
[67017.96] JVM: bklt[1]: setTimeout 30


When I use

UiApplication.getUiApplication().invokeLater(new Runnable()
public void run() {
pushScreen(new ClientScreen());

instead,  the Pop-Up appears but the app crashes afterwards. So I can enable Bluetooth via the popup being in the homescreen.


I have to say I really have not understood when to use this invokeLater stuff so far.


Thanks in advance


BlackBerry Development Advisor
Posts: 15,882
Registered: ‎07-09-2008
My Device: BlackBerry PRIV
My Carrier: Bell

Re: Bluetooth JSR82 / Threads

You should not use code in a screen's constructor that triggers a dialog.


If you want to initiate discovery on startup, perform that operation in a new thread you create in the screen's constructor.

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Super Contributor
Posts: 253
Registered: ‎08-19-2010
My Device: BB10, Playbook, 9900, 9800, 9700, 9550, 9530, 9500, 8700.
My Carrier: TT

Re: Bluetooth JSR82 / Threads

The sample does not work on BlackBerry 9900.


I modify the Github sample code, and then share to everyone.






-Fight with BB10