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
Contributor
dinakel
Posts: 23
Registered: ‎03-30-2011
My Device: Several Simulators
My Carrier: none - simulator only
Accepted Solution

Startup YES/NO Dialog should stop the launchign process of the app

Hi all,

 

I admit, I have posted this question already and gave a lot of code examples on StackOverflow here:

http://stackoverflow.com/questions/10620605/blackberry-show-dialog-on-startup-and-wait-until-dialog-...

 

But I also read peter strange's article here:

http://supportforums.blackberry.com/t5/Java-Development/Sample-quot-Please-Wait-quot-screen-part-1/t...

 

Both didn't help. Since I really need help with this, I hope you forgive me the crossposting. I promise to provide the solution on both platforms as soon as I have one.

 

In short, what I'm trying to do is having a YES/NO dialog on startup of the app. The startup procress should be stopped, until the user clicks yes or no. If he clicks yes a method should be called and after the method has been completely processed, startup should continue.

 

Thanks a lot.

 

Dinakel

Please use plain text.
Developer
maadani
Posts: 729
Registered: ‎05-04-2011
My Device: 9700

Re: Startup YES/NO Dialog should stop the launchign process of the app

You should push a global screen with the MODAL option.

 

This should give you what you need:

http://supportforums.blackberry.com/t5/Java-Development/How-to-do-a-Terms-and-Conditions-popup-and-s...

 

E.

Please use plain text.
Developer
simon_hain
Posts: 16,093
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Startup YES/NO Dialog should stop the launchign process of the app

no need for a global screen, as the application is in the foreground.
just use pushModalScreen, or Dialog.ask or similar.
----------------------------------------------------------
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
Please use plain text.
Contributor
dinakel
Posts: 23
Registered: ‎03-30-2011
My Device: Several Simulators
My Carrier: none - simulator only

Re: Startup YES/NO Dialog should stop the launchign process of the app

Thanks a lot Simon and Maadani!

 

Here is the SSCCE that finally does what I want it to do. I also tried without the test.invokeLater() in the main-method. That doesn't work. Probably this is obvious for you, but I still have some trouble understanding the threading model of BB apps.

I haven't tried with pushModalScreen, mainly because I need a Listener then. This makes the interaction asynchron and I would need another wait/notfiy construct or similar to make the main thread stop and continue, when the Listener gets notified. Am I wrong?

 

Thanks anyway, I will start implementing it in my actual application now and hopefully it works there as well.

 

SSCCE:

package TestDialog;

import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.component.RichTextField;
import net.rim.device.api.ui.container.MainScreen;

public class TestDialog extends UiApplication implements Runnable
{
    /**
     * @param args
     */
    public static void main(final String[] args)
    {

        final TestDialog test = new TestDialog();
        test.invokeLater(test);

        test.enterEventDispatcher();

    }

    public TestDialog()
    {

    }

    public void run()
    {

        final int answer = Dialog.ask(Dialog.D_YES_NO, "continue?");
        //        pushGlobalScreen(new Dialog(Dialog.D_YES_NO, "continue?", 0, null, Dialog.GLOBAL_STATUS), 1, TestDialog.GLOBAL_QUEUE | TestDialog.GLOBAL_MODAL);

        if (answer == Dialog.YES)
        {
            System.out.println("user clicked yes");
        }
        else
        {
            System.exit(0);
        }

        pushScreen(new MyScreen("App loaded"));
    }

    class MyScreen extends MainScreen
    {

        public MyScreen(final String msg)
        {

            final LabelField title = new LabelField("First Screen", LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
            setTitle(title);
            this.add(new RichTextField(msg));

        }

    }

}

 

Please use plain text.
Developer
simon_hain
Posts: 16,093
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Startup YES/NO Dialog should stop the launchign process of the app

a global screen blocks access to other applications, that's why i suggest using a normal popupscreen. Otherwise the user is forced to do whatever you require to use other applications, not a good experience.

to get an overview about the event thread check this:
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
Please use plain text.