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
Forums Advisor I
Posts: 501
Registered: ‎03-01-2013
My Device: BlackBerry Z10

Problem in tapping the button

Hi

In my application , i have three buttons on the main Screen. When i tap the first button, second screen gets open and in that i am sending request to server for the data.

 

The problem is when i tap the button , it takes sometime to open the second screen. I want the second screen gets open immediately as soon as i tap the button.

synchronized (UiApplication.getEventLock())
            {
                if(screen!=null)
                cameraScreen.close();                        
            }

Developer
Posts: 16,998
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Problem in tapping the button

check if your server request runs on a separate thread.
if you run it on the UI thread you block the UI.
see
http://supportforums.blackberry.com/t5/Java-Development/What-is-the-Event-Thread/ta-p/446865
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Forums Advisor I
Posts: 501
Registered: ‎03-01-2013
My Device: BlackBerry Z10

Re: Problem in tapping the button

Hi

I have a separate thread for network activities.In second screen i firstly display the UI and then calling the thread for network activity.

 

Like this....

 

public SecondScreen()

{

//Text box.

//image

//loading image

// ConnectionThread t = new ConnectionThread();

//  t.start();

}

Developer
Posts: 121
Registered: ‎05-31-2012
My Device: 9900
My Carrier: Airtel

Re: Problem in tapping the button

First of all, You post title does not have relevance to your problem.

Secondly, SimonHain has guided you in correct direction.

 

 

Try something like following--

 

public class SecondClass extends MainScreen{
    public SecondClass() {
        fetchData();
    }

    private void fetchData() {
        new Thread(new Runnable() {

            public void run() {
                //getDataFromServer();
            }
        }).start();        
    }
}

 

Rishikesh Singh
Developer
Posts: 16,998
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Problem in tapping the button

i would need to see more actual code (how you show the screen).
creating a new connection thread and calling start on it looks fine.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Highlighted
Regular Contributor
Posts: 66
Registered: ‎08-28-2010
My Device: 9630

Re: Problem in tapping the button

you can use the below code for loading new screen and use the separate class that extends thread class and do the network related activity.

UiApplication.getUiApplication().invokeLater(new Runnable()
{
public void run()
{
// push your second screen.
// pop current screen.
}
});