0
votes

I have a version hit check right after my application gets start. But when simulator is loading its sending the request and all that stuff. After my application starts it give version hit value NULL but after I close the application and open it again it gives the correct value.

1) My Question is that Why is this behavior occurring and what should I do that app starts and version check gives correct value at first attempt!

2) And the app is even not executed by user why its line of codes are executed?????

public MyScreen()  { 
    Bitmap bitmap = Bitmap.getBitmapResource("background.png");
    this.getMainManager().setBackground(
            BackgroundFactory.createBitmapBackground(bitmap)); 

    synchronized (Application.getEventLock()) 
    {
        UiApplication.getUiApplication().invokeLater(new Runnable() 
        {
            public void run() 
            {
                Status.show("Please Wait...", Bitmap.getPredefinedBitmap(Bitmap.INFORMATION), 1000);
                LoginScreen();
            }
        }); 
    }

Now what does it do is that it shows only the background screen and nothing happens no service but when I start it again it works. Whats the problem? Thanks

1
You don't show any code above that's making any webservice calls. If LoginScreen() does that, please show that code. Also, please clarify what you mean by why its line of codes are executed. Do you mean that you see some lines of code in the app run before the user starts it with the normal icon? Which lines of code? The ones you show above? You probably also need to show your main program (the main UiApplication subclass). - Nate
This is the "MyApp" Class code: codepad.org/WiyIf4vy And this is "MyScreen Code" Code: - Ahmad Shahwaiz
Did you mean to post more code here? I only see the link to your MyApp.java, not to the rest of MyScreen. - Nate
Yes, was Disconnected, here is the MyScreen Class Code: codepad.org/CpYsanuY So when I install it in the device/simulator. Before Clicking on the icon it starts sending call to the webservice. And it gives Null Pointer Excception in line 579 "NPE" before clicking the launch icon. And when I don't use the invokeLater then it gives RuntimeException or if I use Dialog box then it says Can't show UI Component over event dispatcher. And After Clicking the Icon it just gives the Background screen and thats it. But closing the app and starting it again does'nt give this behavor and works fine. - Ahmad Shahwaiz
Are you setting Auto-run on startup in your BlackBerry_App_Descriptor.xml file? - Nate

1 Answers

0
votes

If your MyScreen class is actually a kind of Screen (through inheritance), then there's no need for you to synchronize on the event lock in this case. The constructor for a Screen will already be called on the UI thread, so, just simplify your code to:

public MyScreen()  { 
    Bitmap bitmap = Bitmap.getBitmapResource("background.png");
    this.getMainManager().setBackground(
            BackgroundFactory.createBitmapBackground(bitmap)); 

    UiApplication.getUiApplication().invokeLater(new Runnable() 
    {
        public void run() 
        {
            Status.show("Please Wait...", Bitmap.getPredefinedBitmap(Bitmap.INFORMATION), 1000);
            LoginScreen();
        }
    }); 

Also, you might be able to get rid of the invokeLater() call, too, leaving you with this:

public MyScreen()  { 
    Bitmap bitmap = Bitmap.getBitmapResource("background.png");
    this.getMainManager().setBackground(
            BackgroundFactory.createBitmapBackground(bitmap)); 

    Status.show("Please Wait...", Bitmap.getPredefinedBitmap(Bitmap.INFORMATION), 1000);
    LoginScreen();

You would normally use invokeLater() if you just wanted to safely initiate the code inside its run() method from a background thread, or if you wanted to queue it to be run after the constructor finishes.

But, if you're ready for it to happen right away, and you were just using that call to ensure that

 Status.show("Please Wait...", Bitmap.getPredefinedBitmap(Bitmap.INFORMATION), 1000);
 LoginScreen();

was run on the UI thread, then there's no need for that, because as I said, you're already on the UI thread in the MyScreen constructor.

But, I also can't see what you do at the end of your MyScreen constructor, so it's possible that using invokeLater() is appropriate.

Post some more information in response to my comment above, and I'll try to help with more.