2
votes

I am creating a java ME app that uses bluetooth.

No matter how I try to change the current Displayable it does not change.

My app sets a textbox called "devices" as the current displayable in startup and I change current to a list called "devicelist" in a method in another class.

But when I try to change the current back to textbox (devices ) it doesn't change.

I tried using the display object in midlet class and also using gestDisplay in other class. But the List object (deviceList) remains the current Displayable.

update Per my testing, there seems to be some bug. The TextBox (devices) is the current Displayable but when I check isShown it comes as false. Instead the other Displayable: List (deviceList) when tested with isShown comes as true. Although the api specifications suggest that setCurrent method's effect is not immediate, the current Displayable is changing but it is not shown on the screen.And this happens both in the real device and the emulator.

1
if you properly obtain Display object in the instance of your MIDlet class, in startApp - then setCurrent should do what you expect. Your issue is because you've got bugs in your code. Add logging, test, study logs when things go wrong, add more logging and re-test until you get rid of bugs - gnat
yes thats how i got to know that current does not change.And also i see no exceptions.What would be the best way to create logs except make something print in current.? Sorry i'm new to the forum. Shall i post the code here? - akhil_
if you test with emulator, the simplest way is to use System.out.println to trace midlet execution in the console. There are also various logging libraries for Java ME worth considering for testing with real devices, but for emulator system.out.println is just fine - gnat
cannot test with emulator as the app requires to discover a bluetooth service and this service is provided by my pc and a java me device cannot rpovide the services. Sorry, actually i can test this part because it does not require the service. Thanks for the tip though - akhil_
having code in pastebin is not quite welcome at Stack Overflow. Preferred way here is to add relevant code snippets or, better yet, SSCCE (Short, Self Contained, Correct (Compilable), Example) into the question - gnat

1 Answers

1
votes

You found one right part of specification but not all of them - that's why you are confused.

Your understanding that setCurrent method's effect is not immediate is 100% right indeed, that's what API javadocs specify, OK:

  • Display.setCurrent(Displayable):

    ...The change will typically not take effect immediately. It may be delayed so that it occurs between event delivery method calls, although it is not guaranteed to occur before the next event delivery method is called. The setCurrent() method returns immediately, without waiting for the change to take place...

the current Displayable is changing but it is not showngetCurrent

  • Display.getCurrent():

    Gets the current Displayable object for this MIDlet... object returned may not actually be visible... The Displayable.isShown() method may be called to determine whether the Displayable is actually visible on the display.

isShown()

...the fact that you're experiencing delays and especially that this happens even on emulator, makes me feel that there may be design problem in your midlet. I would strongly recommend to check whether there is some "heavyweight" activity that you run in the same thread as UI, blocking it and making it irresponsive.

Avoid heavy load in UI event thread. When there's much to do of something inside of commandAction or keyPressed or pointerPressed etc, just spawn a new thread to do that. If you find this to be the case in your midlet, consider studying this tutorial to find out tow to do it right:

  • Networking, User Experience, and Threads

    This article explains how your MIDlet can make network connections without compromising your user interface. It includes six iterative examples that illustrate multithreaded networking and the use of a wait screen...