0

what i am trying to do is that on click of a button in screen1, i try push the screen2 repeatedly with different images and different Transition Context.

the code is as follows

public void fieldChanged(Field field, int context) 
{
        if(field==slideButton)
        {       
            for(int i=0;i<bitmaps.length;i++)
            {



                slideScreen = new SliderScreen(bitmaps[i]);

                UiApplication.getUiApplication().pushScreen(slideScreen);
                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                UiApplication.getUiApplication().popScreen(slideScreen);

            }

        }
    }
}

Problem is that nothing appears.Is there any other way to achieve this..

1 Answer 1

0

Fixed version of your initial idea:

public void fieldChanged(Field field, int context) {
    if (field==slideButton) {

        final UiApplication app = UiApplication.getUiApplication();

        new Thread(new Runnable() {
            public void run() {
                for (int i = 0; i < bitmaps.length; i++) {
                    final SliderScreen slideScreen = 
                        new SliderScreen(bitmaps[i]);

                    app.invokeAndWait(new Runnable() {
                        public void run() {
                            app.pushScreen(slideScreen);
                        }
                    });

                    try {
                        Thread.sleep(2000);
                    } catch (InterruptedException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }

                    app.invokeAndWait(new Runnable() {
                        public void run() {
                            app.popScreen(slideScreen);
                        }
                    });
                }
            }
        }).start();
    }
}

Your code did not work because the UI thread was sleeping between push and pop, so it has no time/chance to start drawing the screen. Note I moved the entire action into a separate thread. So now the main UI thread has free time to actually make drawing.

1
  • @Manish: Any success with this? Jul 2, 2011 at 21:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.