Question of InvokeLater UiApplication

What is this required if another thread calls the method invalidate to a list field?  He does not seem to be required, works well on the device and the Simulator without it, but seems to conflict with my understanding of it.  I also found that using the method. a RichTextField setText() seems to move back and forth... as a test, I tried on a single RichTextField() and it never crashed, but when I tried it on several RichTextFields I would sometimes get the exception error...

Thank you!

Invalidate() just sets a flag, and I think that it is accessible from outside the event thread.

setText() (and similar) requires that the thread is the thread of the actual event, or another thread that holds the lock of the event.

Tags: BlackBerry Developers

Similar Questions

  • Access a domain of a Thread Manager

    Hello!

    I have a slightly customized vertical field Manager called [u] main [/ u], I want to access from a thread. Maybe that's the first mistake

    Is this possible?

    Whenever I try to open it, I get IllegalStateException thrown by the method called [u] main [/ u].

    I tried a lot of things with the locks, but I was not able to understand what I can do.

    Can you help me?

    I have not tested with a compiler, but it should be something like this (explicit synchronization):

    class Bridge extends Thread
    {
       private StdScreen _screen01;
    
       Bridge(StdScreen screen)
       {
    
           _screen01 = screen;
       }
    
       ... some methods...
    
       public void run()
       {
    
           ...
    
           synchronized(Application.getEventLock())
           {
               _screen01.fieldSelected(someField);
           }
           ...
       }
    }
    

    or like this (runnable and invoke):

    class Bridge extends Thread
    {
    
       private StdScreen _screen01;
    
       Bridge(StdScreen screen)
       {
           _screen01 = screen;
       }
    
       ... some methods...
    
       public void run()
       {
    
           ...
           // since it seems that you don't need to wait until UI
           // thread finishes the job use plain invokeLater
           UiApplication.getUiApplication().invokeLater(new Runnable()
           {
               public void run()
               {
                    _screen01.fieldSelected(someField);
               }
           });
           ...
       }
    }
    

    Hope this helps

  • Question about UiApplication.getUiapplicatin ().

    Hi all,.

    Hope everything goes well. In fact, I want to ask UiApplication.getUiApplication () gives you your application instance (please, correct me if I'm wrong). Let's look at the code

    public class SimpleSmsChatApp extends UiApplication  {
    
        // Constructor
        public SimpleSmsChatApp() {   
    
            //Create the main screen and push it on to the display stack
            SimpleSmsChatMainScreen mainScreen = new SimpleSmsChatMainScreen(chatScreen,  createProfileScreen);
            pushScreen(mainScreen);  
    
        } //end of constructor
    
        public static void main(String[] args) {
    
            //Create an instance of the application
            SimpleSmsChatApp app = new SimpleSmsChatApp();
    
            // Start the event displatch thread
            app.enterEventDispatcher();
    
        } // end of main()
    
    } //end of class SimpleSmsChatApp
    

    It is a main class simple code. Now suppose I have add a method in this class as follows

    public class SimpleSmsChatApp extends UiApplication  {
    
        private CreateProfileScreen createProfileScreen;
        private ChatScreen chatScreen;
    
        // Constructor
        public SimpleSmsChatApp() {   
    
            //Create the main screen and push it on to the display stack
            SimpleSmsChatMainScreen mainScreen = new SimpleSmsChatMainScreen(chatScreen, createProfileScreen);
            pushScreen(mainScreen);  
    
        } //end of constructor
    
            public static void main(String[] args) {
    
            //Create an instance of the application
            SimpleSmsChatApp app = new SimpleSmsChatApp();
    
            // Start the event displatch thread
            app.enterEventDispatcher();
    
        } // end of main()
    
        public ChatScreen getChatScreen() {
    
            if (chatScreen == null) {
    
                chatScreen = new ChatScreen();
    
            }
    
            return chatScreen;
    
        } //end of getChatScreen()
    
          public CreateProfileScreen getCreateProfileScreen() {
    
            if (createProfileScreen == null) {
    
                createProfileScreen = new CreateProfileScreen();
    
            }
    
            return createProfileScreen;
    
        } //end of getChatScreen()
    
    } //end of class SimpleSmsChatApp
    

    Now I have another class in which I have pimples. Suppose that on the button clicks I want to createProfileScreen and window shows. I have code like this

     if (field == searchButton) {
    
         CreateProfileScreen createProfileScreen = UiApplication.getUiApplication().getCreateProfileScreen();                                                                                             UiApplication.getUiApplication().pushScreen(createProfileScreen);
    
     }
    
     if (field == chatButton) {
    
         ChatScreen chatScreen = UiApplication.getUiApplication().getChatScreen(); 
    
         UiApplication.getUiApplication().pushScreen(chatScreen);
    
     }
    

    My question is that

    UiApplication.getUiApplication()
    

    gives you the instance of the same instance I created in my main class i.e. SimpleSmsChatApp. But it gives me the error that cannot find symbol getChatScreen().

    I want to ask that whe

    UiApplication.getUiApplication(
    

    give me the instance of the main class (SimpleSmsChatApp) and I have getChatScreen() and getCreateProfileScreen() in my main class so why it gives me error that cannot find symbol.

    I'm doing this because I want any number of screens I have in my project, I created each instance of the form only once and then call the instance whenever I need fron any class.

    Please clear my confusion about UiApplication.getUiApplication (). No matter what I'm doing wrong and how achieve what I'm trying doesn't mean created instance only once and call it whenever I need any class

    Thank you

    UiApplication.getUiApplication retrieves the current instance of UiApplication.

    Please modify your code to convert, and then call the function like this:

    ((SimpleSmsChatApp)UiApplication.getUiApplication()).getChatScreen();
    
  • a question with interface Runnable?

    Hi all, I have a question with the Runnable interface.

    public void TestFunction(Rnnable rn){  rn.run();}
    
    //create a Runnable objectRunnable new_runnable = new Runable()
    {
      public voi run()  {     //do some thing...  }};
    
    //Call TestFunctionpublic void main(..){   //do some thing...   TestFuntion(new_runnable); /*Will this call make new_runnable run on separate thread? */   //do some thing...}
    
    
    

    My goal is to create a TestFunction with the setting is another function to perform, and I want to run on the same thread.

    If I use passable is a parameter, it will be Runnable.run () run on separate thread or the same thread by Thread that calls TestFunction()?

    Thank you very much!

    Yes, it runs on the same thread because you call the run method directly if you want it to run on its own thread you need to run Application.invalokeLater (runnable) or UiApplication.invokeLater (runnable) or pass to a thread object Thread (runnable) m:System.NET.HttpListener.start (new).

  • UiApplication using PopupScreen

    Hi all

    This is my first post on this amazing forum. I read through many large threads with lots of answers to the questions I had in my short time developing applications for the BlackBerry smartphone. Unfortunately, I hit my first stumbling block, which I'm sure will be very easy, but hey, we all start somewhere.

    The question that I'm doing the experience simply creates a PopupScreen in the mainevent thread and wait for user input before continuing. In my days of Swing I just use an observable model and notify the application of change, but I seem to have trouble with this concept here. I tried to use the pushModalScreen and the pushGlobalScreen of the UiApplication class methods, but both give me a runtime... error pushGlobalScreen called by thread of non-event.

    It seems to me missing something probably just in front of me, but I would appreciate help on this. I just use this example using the 9000 Simulator that is packed with the JDE v4.6

    public static void main(String[] args) {
            MyApp app = new MyApp();
            app.enterEventDispatcher();
        }
    
        MyApp() {
            final PromptTest prompt = new PromptTest();
            invokeLater(new Runnable() {
                public void run() {
                    pushGlobalScreen(prompt,1,UiApplication.GLOBAL_MODAL);
                }
            });
            continueProcess();
        }
    
        public void continueProcess() {
        // do something with input from PopupScreen
        }
    }
    

    Thank you.

    Well, I'm a little bit embarrassed. I have solved my problem. Using just pushScreen, like any other approach and all simply migrate code to deal with in my fieldChangeListener. I don't know what I thought earlier. I'm sorry to have lost someone's time on this one.

  • Question no doubt multi-threaded

    Greetings!

    Don't know what kind of problem I face, but still very interesting.

    I have a UiApplication who starts a thread to listen to incoming SMS and respond automatically. This same class implements PhoneListener as below:

    public class SMSSenderReceiver extends Thread implements PhoneListener {
    
        private static DatagramConnection _dc;
        private static int _callIdIncoming;
        private static int _callIdAnswered;
        public static String _phoneNumber;
    
        static {
        try {
            _dc = (DatagramConnection) Connector.open("sms://");
            } catch (IOException e) {
                System.out.println(e);
            }
        }
    
        public SMSSenderReceiver() {
            super();
            _callIdIncoming = -1;
            _callIdAnswered = -1;
            Phone.addPhoneListener(this);
        }
    
        public void run() {
            try {
                for (;;) {
                    Datagram d = _dc.newDatagram(_dc.getMaximumLength());
                    _dc.receive(d);
                    String address = d.getAddress();
                    if (address.startsWith("//")) {
                        address = address.substring(2);
                    }
                    String answer = getResponseByPhone(address);
                    if (answer != null) {
                        answer.getBytes();
                        Datagram returnpacket = _dc.newDatagram(_dc
                                .getMaximumLength());
                        returnpacket.setAddress(d.getAddress());
                        returnpacket.setData(answer.getBytes(), 0, answer.length());
                        _dc.send(returnpacket);
                    }
                }
            } catch (IOException ioe) {
                System.out.println(ioe);
                Phone.removePhoneListener(this);
            }
        }
    
        private static String getResponseByPhone(final String phone) {
            TextResponses tr = TextResponses.getInstance();
            MultiMap mm = tr.getResponses();
            Enumeration valuesEnum = mm.keys();
            while (valuesEnum.hasMoreElements()) {
                String element = valuesEnum.nextElement().toString();
                if (mm.containsValue(element, phone)) {
                    return element;
                } else {
                    continue;
                }
            }
            return null;
        }
    
        //  public void missedCallSMSSender(final String address) {
        //      try {
        //          if(_callIdAnswered != _callIdIncoming){
        //              //              if (address.startsWith("//")) {
        //              //                  address = address.substring(2);
        //              //              }
        //              String answer = this.getResponseByPhone(address);
        //              if (answer != null) {
        //                  answer.getBytes();
        //                  Datagram returnpacket = _dc.newDatagram(_dc
        //                          .getMaximumLength());
        //                  returnpacket.setAddress("//" + address);
        //                  returnpacket.setData(answer.getBytes(), 0, answer
        //                          .length());
        //                  _dc.send(returnpacket);
        //              }
        //              _callIdAnswered = _callIdIncoming = -1;
        //              //_phoneCallsHash.remove("" + _callIdIncoming);
        //          }
        //      } catch (Exception e) {
        //          System.out.println(e);
        //      }
        //  }
    
        public void callIncoming(final int callId) {
            if(_callIdIncoming != callId){
                UiApplication.getUiApplication().invokeLater(new Runnable(){
                    public void run() {
                        _callIdIncoming = callId;
                        PhoneCall phoneCall = Phone.getCall( callId );
                        _phoneNumber = null;
                        try {
                            _phoneNumber = phoneCall.getDisplayPhoneNumber();
    
                            String tempNumber = null;
                            for(int i = _phoneNumber.length() -1 ;i >= 0; --i) {
                                if(Character.isDigit(_phoneNumber.charAt(i))){
                                    tempNumber = _phoneNumber.charAt(i) + ((tempNumber == null) ? "" : tempNumber) ;
                                }
                            }
                            _phoneNumber = tempNumber;
    
                            System.out.println("**bleep** Phone Number: " + _phoneNumber);
                        } catch(NullPointerException npe) {
                            _phoneNumber = "0";
                            System.out.println("NULL!!!!" + npe);
                        }
                    }
                });
            }
        }
    
        public void callAnswered(int callId) {
            _callIdAnswered = callId;
        }
    
        public void callDisconnected(int callId) {
            UiApplication.getUiApplication().invokeLater(new Runnable(){
                public void run() {
                    //System.out.println("**bleep** Phone Number: " + _phoneNumber);
                    //SMSSenderReceiver.this.missedCallSMSSender(_phoneNumber);
                    String address = _phoneNumber;
                    if(_callIdAnswered != _callIdIncoming){
                        //                  if (address.startsWith("//")) {
                        //                      address = address.substring(2);
                        //                  }
                        String answer = getResponseByPhone(address);
                        if (answer != null) {
                            answer.getBytes();
                            try {
                                Datagram returnpacket = _dc.newDatagram(_dc.getMaximumLength());
                                returnpacket.setAddress("//" + address);
                                returnpacket.setData(answer.getBytes(), 0, answer
                                        .length());
                                _dc.send(returnpacket);
                            } catch(Exception e) {
                                System.out.println(e);
                            }
                        }
                        _callIdAnswered = _callIdIncoming = -1;
                    }
                }
            });
        }
    ...
    

    The goal is to send an SMS for each missed call. Thus, on incomingCall while I get caller Id and phone number assign them static variables. If the call is answered I catch the call id also. Once the call is disconnected I just check the id of appeal responded and id entering in case they differ from each other, I got a call from miss and I send a SMS.

    The problem is once the callDisconneted is called, I don't have the value of _phoneNumber. On incomingCall I could see the number, but not after all. Why? Seems to be a fundamental basis on the multi-thread.

    Anyone know what is happening?

    Thanks in advance!

    --

    This question probably has to do with the fact that the listener to call is actually coming in your code on the phone application thread. Each application gets a copy separate from the static context. As a result, you won't see the same data when you access this variable in your own application process.

    You can probably here either: (a) send yourself a form of global event listener call, then pick up the event in your own process, or (b) use the runtime store to keep the value so that the two processes can * see * it.

  • Occurrence of-> UncaughtException UiApplication

    Hi guys.

    I certify the source code.

    My application has a screen.

    The main point is to add several LabelFields to screen in thread.

    public class MyApplication extends MainScreen {
    
         public MyApplication() {           ..............     }
    
         public void addInfoField(LabelField info) {           this.add(info);     }
    
         private class AddInfoFields extends Thread {
    
               public void run() {
    
                      for(int i = 0; i < 150; i++) {                       ....                       final LabelField info  = new LabelField(".....");                       UiApplication.getUiApplication().invokeLater(new Runnable() {                            public void run() {                                  addInfoField();                            }                       }                  }           }     }}
    

    My question: is there presence rising UncaughtException (such as the queue is full) repeatedly for () ?

    Thank you guys.

    Yes, exactly. You're hungry the UI of event thread. Accordingly, is filled with the message queue and the OS kills your app and a trace of the stack of the forces.

    The form of the device stack trace and look at the object that caused the exception.

  • Questions about discussions...

    Hello

    I have a new app to do that requires network access.

    I have read this EXCELLENT post from peter_strange:

    http://supportforums.BlackBerry.com/T5/Java-development/connecting-your-BlackBerry-http-and-socket-c...

    Because I can't use BIS - B because I'm not a partner of the Alliance, I wanted to take a look at the new OS 5.0 network API and see how it works.

    I know that network connections should be performed in a separate thread.

    I'm far from being an experienced Blackberry developer... so I have a few questions about discussions.  I looked around the Internet, read on the forum, read the documentation, did some tests and so far, I came up with this code:

    SerializableAttribute public class HTTPConnection extends UiApplication {}
    Public Shared Sub main (String [] args) {}
    HTTPConnection PAP = new HTTPConnection();
    theApp.enterEventDispatcher ();
    }

    public HTTPConnection() {}
    pushScreen (new HTTPConnectionScreen());
    }
    }

    class HTTPConnectionScreen extends form {}
    public HTTPConnectionScreen() {}
    setTitle ("HTTPConnection");
    Add (new RichTextField ("choose a type of connection :"));

    final RadioButtonGroup = new RadioButtonGroup() rbGroup;
    RadioButtonField radioButtonF1 = new RadioButtonField ("Direct TCP", rbGroup, false);
    RadioButtonField radioButtonF2 = new RadioButtonField ("WAP 1.0/1.1", rbGroup, false);
    RadioButtonField radioButtonF3 = new RadioButtonField ("WAP 2.0", rbGroup, false);
    RadioButtonField radioButtonF4 is new RadioButtonField ("BES/MDS", rbGroup, false);.
    RadioButtonField radioButtonF5 = new RadioButtonField ("BIS-B", rbGroup, false);
    RadioButtonField radioButtonF6 = new RadioButtonField ("WiFi", rbGroup, false);
    Add (radioButtonF1); Add (radioButtonF2); Add (radioButtonF3); Add (radioButtonF4); Add (radioButtonF5); Add (radioButtonF6);
             
    FieldChangeListener listener = new FieldChangeListener() {}
    ' Public Sub fieldChanged (field field, int context) {}
    ConnectionThread ct = new ConnectionThread (rbGroup.getSelectedIndex () + 1);
    CT. Start();
    }
    };
             
    ButtonField buttonField = new ButtonField ("Connect", ButtonField.CONSUME_CLICK);
    buttonField.setChangeListener (listener);
    Add (buttonField);
    }

    / * method of onSavePrompt override default to avoid being asked if I want to record every time * /.
    protected boolean onSavePrompt() {}
    Returns true;
    }
    }

    class ConnectionThread extends Thread {}
    private int transportType;
    public ConnectionThread (int n) {}
    transportType = tt;
    }
        
    public void run() {}
    ConnectionFactory connFact = new ConnectionFactory();
    ConnectionDescriptor connDesc = connFact.getConnection ("URL", transportType, null);
    If (connDesc! = null) {}
    try {}
    HttpConnection httpConn = (HttpConnection) connDesc.getConnection ();
    httpConn.setRequestMethod (HttpConnection.POST);
    httpConn.setRequestProperty ("Content-Type", "application/x-www-formulaires-urlencoded");
    OutputStream out = httpConn.openOutputStream ();
    out. Write (Integer.ToString (transportType). GetBytes());
    int responseCode = httpConn.getResponseCode ();
    If (responseCode == HttpConnection.HTTP_OK) {}
    UiApplication.getUiApplication () .invokeLater (new Runnable() {}
    public void run() {}
    Dialog.Alert ("- SUCCESSFUL CONNECTION-");
    }
    });
    }
    If (httpConn! = null) httpConn.close ();
    } catch (IOException e) {}
    System.Err.println ("IOException Caught:" + e.getMessage ());
    }
    }
    }
    }

    In fact, this code works very well... but I want to improve it, and I have a few questions:

    1. I think that right now, every time I click on the 'Connect' button, I start a new thread. I would like to end this thread in the "run" method, but I don't really know how to access the variable 'ct' from there.   Counsel on how to do it?  Or maybe always use the same thread until my application is closed?

    2. in the FieldChangeListener of my "Submit" button, I want to access the value of radio box.  I did work, but I had to do my 'final' variable  What is the right way to do it?

    3 - to display a dialog box with 'Successful connection', I just wanted to write something in my main screen.  How I do that?

    I'm just a bit confused as to just what set up when you use a separate thread.

    Thanks for your advice!

    Edit: Hidden URL I connect to...

    That's what I call a good question! (now I'm wondering why the forums do not work with opera correctly, in any case, here my baldy to the answer format): 1. your thread "dies" when it's over, no need to close it. 2 Yes 3. You can use a reminder. See for example http://www.javaworld.com/javaworld/javatips/jw-javatip10.html

  • UiApplication.getEventLock () while alread in case of discussion?

    Hi people,

    I have a busy indicator, which is sometimes called from threads of the event and sometimes by background threads.

    Question: Although the extreme example below seems to work, does anyone know of an official RIM statement on the call of the lock of the event from somewhere that happens so that the event thread (as when a user presses a button)?

    Extreme example to get the lock event while in the wire of the event

    UiApplication.getUiApplication () .invokeLater (new Runnable() {}
    public void run() {}
    {Synchronized (UiApplication.getEventLock ())}

    SOME WORK

    }

    }
    });

    Thank you

    I think that it is harmless to synchronize the lock of the event when already on the thread of the event. However, you can always check by using Application.isEventDispatchThread () (or Application.isEventThread (), if you have a ref for instance practice).

  • Question touch event for mutil - Manager on a screen

    Hi all

    I will say the case:

    I have a screen there is a main VerticaFieldManager that holds two VerticalFieldManager and a field

    the two children-VerticalFieldManagers hold some LabelField.

    When one of them is selected, it will be lit high.

    Then, extending from screen and override touchEvent() and shows a "Hit" said dialog and highlight the OK field.

    because the touchEvent is a shipped process, where the touchEvent occur, each field will receive this event.it never check what field is developed and send the event in this area, (if I'm wrong, please advice).

    Here's the question.

    When user getX and getY to get point touch, then the user getFieldAtLocation on crib, if X / is greater that the extensions Manager, RIM API returns the field expanded.

    This does not look good.

    Here is my source code:

    /*
     * VFMTester.java
     *
     * © , 2003-2008
     * Confidential and proprietary.
     */
    import net.rim.device.api.ui.component.*;
    import net.rim.device.api.ui.*;
    import net.rim.device.api.ui.container.MainScreen;
    import net.rim.device.api.ui.UiApplication;
    import net.rim.device.api.ui.component.*;
    import net.rim.device.api.system.*;
    import net.rim.device.api.servicebook.*;
    import net.rim.device.api.ui.container.*;
    
    /**
     *
     */
    public class VFMTester extends UiApplication{
        public static void main(String args[]){
            UiApplication app = new VFMTester();
            app.enterEventDispatcher();
        }
        VFMTester() {
            pushScreen(new AScreen());
        }
    
        class AScreen extends MainScreen
        {
            VerticalFieldManager vfm;
            public AScreen()
            {
                super();
                vfm = new VerticalFieldManager();
                vfm.add(new LabelField("Test",Field.FOCUSABLE));
                VerticalFieldManager v1 = new TouchVerticalFieldMananger1();
                for(int i=0;i<10;i++){
                    v1.add(new LabelField("F" + String.valueOf(i+1),Field.FOCUSABLE));
                }
                VerticalFieldManager v2 = new TouchVerticalFieldMananger2();
                for(int i=0;i<10;i++){
                    v2.add(new LabelField("S" + String.valueOf(i+1),Field.FOCUSABLE));
                }
                vfm.add(v1);
                vfm.add(v2);
                this.add(vfm);
            }
            public boolean trackwheelClick(int time, int status){
                Dialog.alert("click");
                return true;
            }
            protected boolean touchEvent(TouchEvent te){
                UiApplication.getUiApplication().invokeLater(new Runnable()
                {
                    public void run()
                    {
                        Dialog.alert("touched!");
                    }
                });
                return super.touchEvent(te);
            }
        }
    
        class TouchVerticalFieldMananger1 extends VerticalFieldManager
        {
            TouchVerticalFieldMananger1()
            {
                super();
            }
            public boolean touchEvent(TouchEvent te)
            {        if(!this.isFocus()) return true;            switch(te.getEvent())
                {
                    case TouchEvent.CANCEL:
                        System.out.println("CANCEL");
                    break;
                    case TouchEvent.CLICK:
                        System.out.println("CLICK");
                    break;
                    case TouchEvent.DOWN:
                        System.out.println("DOWN");
                    break;
                    case TouchEvent.GESTURE:
                        System.out.println("GESTURE");
                    break;
                    case TouchEvent.MOVE:
                        System.out.println("MOVE");
                    break;
                    case TouchEvent.UNCLICK:
                        System.out.println("UNCLICK");
                    break;
                    case TouchEvent.UP:
                        System.out.println("UP");
                    break;
                }
                if(!te.isValid()) return true;
                int x = te.getX(1);
                int y = te.getY(1);
                int index = this.getFieldAtLocation(x,y);
                if(index < 0 ) return true;
                Field f = getField(index);
                f.setFocus();
                this.invalidate();
                return true;
            }
        }
        class TouchVerticalFieldMananger2 extends VerticalFieldManager
        {
            TouchVerticalFieldMananger2()
            {
                super();
            }
            public boolean touchEvent(TouchEvent te)
            {
    
                if(!this.isFocus()) return true;            switch(te.getEvent())
                {
                    case TouchEvent.CANCEL:
                        System.out.println("CANCEL");
                    break;
                    case TouchEvent.CLICK:
                        System.out.println("CLICK");
                    break;
                    case TouchEvent.DOWN:
                        System.out.println("DOWN");
                    break;
                    case TouchEvent.GESTURE:
                        System.out.println("GESTURE");
                    break;
                    case TouchEvent.MOVE:
                        System.out.println("MOVE");
                    break;
                    case TouchEvent.UNCLICK:
                        System.out.println("UNCLICK");
                    break;
                    case TouchEvent.UP:
                        System.out.println("UP");
                    break;
                }
                if(!te.isValid()) return true;
                int x = te.getX(1);
                int y = te.getY(1);
                int index = this.getFieldAtLocation(x,y);
                if(index < 0 ) return true;
                Field f = getField(index);
                f.setFocus();
                this.invalidate();
                return true;
            }
        }
    }
    

    1:

    If the user has first select a field on one of them VerticalFieldManager, it will always be there and cannot be changed to the other domain.

    2:

    even if I check the field has focus or not, but it doesn't work anymore.

    Is there something wrong on my source code? or logical is false, or my understanding is wrong?

    Any advice pls.

    Thank you.

    We see this issue as well. Our workaround for this is to check the coordinates x, y of touch to make sure that they are within the scope of the current field, and then re - delegate the event so if x is outside the scope of the field.

  • InvokeLater Eclipse flags as undefined

    I try to make the LBS_LAB (location and GPS) laboratory works, using the ecliptic and 4.5 of the API.

    The test application has two classes, the class of the main application and the class LBS_LAB. The main passage is a pushScreen (new LBSScreen());

    The invokeLater is in a method:

    Public Sub log (final String msg) {}
    invokeLater (new Runnable() {}
    public void run() {}
    _logField.SetText (_logField.GetText () + "\n" + msg);
    }
    });
    }

    The project generates no locks Eclipse complains "invokeLater is undefined for the type of LBSScreen.

    Any ideas what I am doing wrong?

    invokelater is a method of application, not the screen.

    You can use UiApplication.getUiApplication () .invokeLater in many cases

  • Custom menu item at the request of Message: two questions

    I try to add a custom menu to the Blackberry message request and get two questions:

    1. When you click the custom menu, the "Application.getApplication () .requestForeground (); method call does not call the main() method of my application "DemoMI".
    2. If I changed the method of

    Application.getApplication () .requestForeground)

    TO

    ApplicationManager.getApplicationManager () .runApplication (app); Where app is the "DemoMI" application descriptor

    Will be called the main() method. However, how can I make the subject of the Message around in the method "run" for the application "com.demo.DemoApp"?  I tried to use a static variable 'mi ContactsDemoMenuItem', but I've always had "null" value when the "main()" is called.

    My environment:

    • JDE: 4.2.0
    • Feature: Pearl 8100 with OS 4.2.0
    import net.rim.device.api.system.*;
    import net.rim.device.api.ui.component.Dialog.*;
    import net.rim.blackberry.api.menuitem.*;
    import net.rim.blackberry.api.pdap.*;
    import javax.microedition.pim.*;
    import net.rim.blackberry.api.mail.Message;
    import net.rim.device.api.ui.UiApplication;
    import net.rim.device.api.ui.*;
    import net.rim.device.api.ui.component.*;
    import net.rim.device.api.ui.container.*;
    
    public final class DemoMI extends Application
    {
        private static final String ARG_LAUNCH_CONTACT_DEMO = "1";
        private static  ContactsDemoMenuItem mi;
        public static void main(String[] args)
        {
            if(args == null || args.length == 0)
            {
                DemoMI app = new DemoMI();
                app.enterEventDispatcher();
            }else
            {
                String appToLaunch = args[0];
                if(ARG_LAUNCH_CONTACT_DEMO.equals(appToLaunch))
                {
                   new com.demo.DemoApp(mi.getMessage()).enterEventDispatcher();
                }
            }
        }
    
        DemoMI()
        {
            long locationToAddMenuItem = ApplicationMenuItemRepository.MENUITEM_EMAIL_VIEW ;
            ApplicationMenuItemRepository amir = ApplicationMenuItemRepository.getInstance();
            ApplicationDescriptor app = ApplicationDescriptor.currentApplicationDescriptor();
    
            app = new ApplicationDescriptor(app, new String[]{ARG_LAUNCH_CONTACT_DEMO});
            mi = new ContactsDemoMenuItem(app);
            amir.addMenuItem(locationToAddMenuItem, mi);
            System.exit(0);
        }
    
        private static class ContactsDemoMenuItem extends ApplicationMenuItem
        {
            ApplicationDescriptor app;
            Message msg;
            ContactsDemoMenuItem(ApplicationDescriptor app)
            {
                super(20);
                this.app = app;
            }
    
            public String toString()
            {
                return "My Menu Item";
            }
    
            public Message getMessage()
            {
                return msg;
            }      
    
            public Object run(Object context)
            {
                if ( context instanceof Message )
                {
                    msg = (Message)context;
                    try
                    {
    
                        Application.getApplication.requestForeground();
                        //ApplicationManager.getApplicationManager().runApplication(app);
                    }catch(Exception e)
                    {
                        e.printStackTrace();
                    }
    
                 } else
                 {
                    throw new IllegalStateException( "Context is null, expected a Contact instance");
                 }
                 return null;
            }
        }
    }
    

    What you see is the expected behavior.  The ApplicationMenuItem runs in a different process where your application was run.  You have two options.

    You can store the subject of the Message in the RuntimeStore when the ApplicationMenuItem is called.  Your application you are undertaking could then read the subject of the Message of the RuntimeStore.

    Or you can create an application based on the drawing below:

    How to allow - a listener in the background to detect and update a GUI application
    Article number: DB-00406

    http://www.BlackBerry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800451/800783/How_To _...

  • The narrow question dialog box...

    Hi, I have problem attempts to display a user dialogue until the app close because no SDCard in simulation/gear, when I use this code in the homescreen class

    if( ! SDCard ){
    errorDialog("no SD Card Exiting ...");
    system.Exit(0);
    }
    
    public static void errorDialog(final String message) {
            UiApplication.getUiApplication().invokeLater(new Runnable() {
                public void run() {
                    Dialog.inform(message);
                }
            });
        }
    

    just soft close and no display of the dialog box.

    I don't know what to do...

    Unfortunately, I think that the problem here is perhaps the position of this control in your startup.

    I have applications that do this kind of check on startup.  But instead of trying to use a dialog in the way that you are, they actually start the Application and press an error to the user screen.  When this form is closed, the Application ends.  If the Application starts as normal, it enters the dispatcher of events as usual, it just display another screen to the normal start screen.  This means that the approach of a normal startup create a UiApplication and pushing a screen is used.

    I suspect that you are trying to make this review as part of your treatment of main() and it will not work because your Application does not exist or has not entered the event dispatcher.

  • Question about FieldChangeListener

    Finally, I'm going back to rewrite the custom PopupScreen that I created for a blackberry app staff.

    I had a question on a FieldChangeListener I set myself for a button.

    The code looks like this:

    FieldChangeListener fcl = new FieldChangeListener()
    {
      public void fieldChanged(Field field, int context)
      {
        fieldChangeNotify(cancel) //cancel is a public static final int
        close();
      }
    };
    
    ButtonField.setChangeListener(fcl);
    

    My question is this: how to retrieve the context of int fieldChangeNotify (int context) value if the listener is attached to the key?

    I am tempted to write a method that mimics the method getSelectedValue() of the dialog class.

    I just wrote to follow him, not production code, but I need something similar to what you want (a dialog box I could put things in).  I hope you can use it, and it shows you how to enable a button in a return code.

    Note that the questionField is optional, basically, the idea is that this screen will be used when it is necessary to confirm an action and collect additional information.  You can ignore it.

    Here is an example of using the screen - I have; ve just done upwards, so please forgive the errors:

    BasicEditField _questionField = new BasicEditField ("reason for Deferring:", "");
    Create the popup to confirm the defer
    ConfirmActionPopupScreen caps = new ConfirmActionPopupScreen ("Confirm Report", _questionField);
    int response = caps.doModal ();
    If (int ==-1) {}
    cancelled
    } else {}
    Oudit
    String pattern = _questionField.getText ();
    ...
    }

    And here is the screen.  Note that I had to change a few things that are specific to what I do, so it would not work, but you get the idea.

    I hope it works for you.

    class ConfirmActionPopupScreen extends PopupScreen
                                   implements FieldChangeListener {
    
        private ButtonField _okButton = new ButtonField("OK");
        private ButtonField _cancelButton = new ButtonField("Cancel");
        private BasicEditField _questionField = null;
    
        private int _returnCode = -1; // Default to Cancel value
    
        //statics ------------------------------------------------------------------
        private static ResourceBundle _resources = ResourceBundle.getBundle(UIResource.BUNDLE_ID, UIResource.BUNDLE_NAME);
    
        public ConfirmActionPopupScreen(String confirmString, BasicEditField questionField) {
            super(new VerticalFieldManager(),Field.FOCUSABLE);
            // Question Icon and text on top
            HorizontalFieldManager hfm = new HorizontalFieldManager();
            hfm.add(new BitmapField(Bitmap.getPredefinedBitmap(Bitmap.QUESTION), BitmapField.FIELD_LEFT));
            hfm.add(new LabelField(" ")); // Just to space it a bit
            hfm.add(new RichTextField(confirmString, RichTextField.FIELD_HCENTER | RichTextField.FIELD_VCENTER ));
            this.add(hfm);
            this.add(new SeparatorField());
            // Optional Question
            _questionField = questionField;
            if ( _questionField != null ) {
                this.add(_questionField);
                this.add(new SeparatorField());
            }
            // Buttons at bottom
            hfm = new HorizontalFieldManager(Field.FIELD_HCENTER);
            hfm.add(_okButton);
            _okButton.setChangeListener(this);
            hfm.add(_cancelButton);
            _cancelButton.setChangeListener(this);
            add(hfm);
    
            // Focus on Question or Cancel Button
            if ( _questionField != null ) {
                _questionField.setFocus();
            } else {
                _cancelButton.setFocus();
            }
        }
    
        /**
         * Diaplay this Screen and wait for response
         * @return indicator of selected button
         */
        public int doModal() {
            UiApplication.getUiApplication().pushModalScreen(this);
            return _returnCode;
        }
    
        /**
         * Only used to process ESC as Cancel
         */
        public boolean keyChar(char key, int status, int time) {
            //intercept the ESC key - exit the app on its receipt
            boolean retval = false;
            switch (key) {
                case Characters.ESCAPE:
                    _returnCode = -1;
                    close();
                    return true;
            }
            return super.keyChar(key,status,time);
        }
    
        public void close() {
            UiApplication.getUiApplication().popScreen(this);
        }
    
        /**
         * Listen for Button press, and process accordingly.>
         */
        public void fieldChanged(Field field, int context) {
            if ( context == FieldChangeListener.PROGRAMMATIC ) {
                return;
            }
            if ( field == _cancelButton ) {
                _returnCode = -1;
                close();
            } else
            if ( field == _okButton ) {
                if ( _questionField != null ) {
                    // Make sure there is some data entered
                    String temp = _questionField.getText();
                    if ( temp == null || temp.length() < 1 ) {
                        Status.show("Input required, please update \"" + _questionField.getLabel() + "\"");
                        _questionField.setFocus();
                        return;
                    }
                }
                _returnCode = 0;
                close();
            }
        }
    
    }
    
  • TimerTask calling UiApplication.getEventLock)

    I use a Timer object for several TimerTask objects that are run at various intervals (a few times per second, approximately every 30 seconds, etc, so nothing urgent). These objects TimerTask do very little work but they access various areas (e.g., setting the text of an EditField), and they call UiApplication.getEventLock () prior to do. And it works fine, no problem.

    However, in order to ensure I'm good things, because TimerTask or objects of a Timer object to follow very quickly, calling UiApplication.getEventLock () would be a problem, as it can effectively block thread of the Timer object, which is supposed to "finish quickly." Thank you

    The worst that will happen is that tasks planned for the future will be delayed in their execution. If your tasks are not urgent, then don't worry in this regard. In any case, nothing on the thread of the event is supposed to take long, either, so the wire from the timer should not have to wait a lot to synchronize the lock.

    If this is a concern, you can always use invokeLater rather than synchronize the lock of the event.

Maybe you are looking for

  • My problem is a messed up MBR?

    I have a similar problem to this subject [help] can not boot Windows (8.1) after resizing partition but I'm not completely sure, that my problem is the same, so I don't want to try the steps until I know if this will help. I've just updated to El Cap

  • DV7-6c95dx: WINDOWS 10 - RECOVER W7

    HAVE A 6C95DX DV7 WITH WINDOWS 10 ON IT (HAS BEEN UPDATED 10 B4 I GOT IT)-IN THE PAST I HAD ANOTHER ONE OF THE SAME MODEL WITH UBINTU MACHINE ON IT AND USED MY SET OF RECOVERY DISKS FOR THE 6C95DX TO RETRIEVE THE W7 AND THE UBINTU DISAPPEARED AND EVE

  • Satellite 5200-device display 801:Quick switch (Fn + F5)

    I have a problem regarding the fast display device switching "pressing the (Fn) with (F5)" nothing happen as usual... does everything body knows how to fix it! Thanks in advance. my laptop is 5200-801 with Nvidia 460Go with 46 MB.

  • battery 9 cells X 220: Sanyo or LGC?

    Hi all! I tried to search past issues by comparing the battery 9 cells Sanyo and LGC, but were unsuccessful. In our office, I made the choice to get a new Sanyo 9 cells (Japan made, completed in China) or LGC (Korea, completed in China) battery. Whic

  • Download folder to System32 path instead of SysWOW64 path Points

    It is a long-standing problem that I ignored and circumvented for years. But now I plan an upgrade to Windows 10 and think I would ask for trouble if I don't fix it all first. The problem is that my download folder is pointing to C:\Windows\System32\