×

Discussion Board

Results 1 to 13 of 13
  1. #1
    Registered User
    Join Date
    Jun 2011
    Location
    Nasik India
    Posts
    39

    Post Command Action for alert

    Hello Everyone,

    I am developing a j2me app in which user can download mp3 files from internet.... User may cancel downloading....So i am provided cancel button on downloaing form.......If user selects cancel command then he is provoided with confirmation alert box with "yes" and "No" commands.

    My problem is that flow cannot be move further if user selects yes or no command. I think the flow of program is already in command action so it cannot invoke other command..

    public void commandAction(Command command, Displayable displayable)
    {
    if (command == downloadCancel)
    {
    alert1.setCommandListener(this);
    alert1.addCommand(cancelYes);
    alert1.addCommand(cancelNo); ;
    alert1.setString("Do you want to cancel?" );
    Displayable d = getDisplay().getCurrent();
    switchDisplayable(alert1, d);

    }
    else if (command == cancelYes)
    {

    //flow never comes here even if user selects cancelYes command when alert is prompted.
    //some code which cancels downloading
    }
    }

    I know am missing something very basic, like switchdisplayable() ......

    Thanks in Advance.....

  2. #2
    Registered User
    Join Date
    Jun 2011
    Location
    Nasik India
    Posts
    39

    URGENT Re: Command Action for alert

    How long I have to get answer for this one......??

    Developers please help me.......Please let me know if you need more info about my problem......

  3. #3
    Registered User
    Join Date
    Dec 2010
    Posts
    39

    Re: URGENT Re: Command Action for alert

    Hi this is a working code
    public void showExitAlert(){
    Alert alert = new Alert("Are you Sure?","Want to Exit...",null,AlertType.WARNING);
    cmdYes = new Command("Yes",Command.OK,0);
    cmdNo = new Command("No",Command.EXIT,0);
    alert.setTimeout(Alert.FOREVER);
    alert.addCommand(cmdYes);
    alert.addCommand(cmdNo);
    alert.setCommandListener(this);
    display.setCurrent(alert,d);
    }
    if (command == downloadCancel){
    showExitAlert();
    }else if (command == cancelYes){
    //flow never comes here even if user selects cancelYes command when alert is prompted.
    //some code which cancels downloading
    }

  4. #4
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Re: URGENT Re: Command Action for alert

    Quote Originally Posted by nazar.ooty View Post
    if (command == downloadCancel){
    showExitAlert();
    }else if (command == cancelYes){
    //flow never comes here even if user selects cancelYes command when alert is prompted.
    //some code which cancels downloading
    Please note that the above quoted code must be inside the commandAction() and not any other method. Did you implement the commandAction() method?
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  5. #5
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    3,087

    Re: URGENT Re: Command Action for alert

    Add this method in your code -

    public void commandAction(Command cmd, Displayable arg1) {
    if (cmd== downloadCancel){
    showExitAlert();
    }else if (cmd== cancelYes){
    //flow never comes here even if user selects cancelYes command when alert is prompted.
    //some code which cancels downloading
    //System.out.println("I am here in cancel flow");
    }

    }

    It should work as expected.
    thanks,
    ~Amitabh
    (Champion of the Month -Aug'13)
    Follow me on my blog for Innovative Mobile Apps

  6. #6
    Registered User
    Join Date
    Jun 2011
    Location
    Nasik India
    Posts
    39

    Re: Command Action for alert

    Thank you Everyone for your valuable help........I have written everything in CommandAction() only. I Have also tried showExitAlert() function given by nazar.ooty...... Its functionality is exactly same as my code.....My problem is that alert box appear with two button YES & NO when user clicks on Cancel button, but even if he selects any one of those two commands nothing will happen...alert box will never disappear even if user selects any command.....If I remove alert1.setCommandListener(this); from the code then alert box will dis-appear if user selects any one of those two commands....

  7. #7
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Re: Command Action for alert

    Quote Originally Posted by vishal.vpb View Post
    Thank you Everyone for your valuable help........I have written everything in CommandAction() only. I Have also tried showExitAlert() function given by nazar.ooty...... Its functionality is exactly same as my code.....My problem is that alert box appear with two button YES & NO when user clicks on Cancel button, but even if he selects any one of those two commands nothing will happen...alert box will never disappear even if user selects any command.....If I remove alert1.setCommandListener(this); from the code then alert box will dis-appear if user selects any one of those two commands....
    Share you code here so that we can have a look and check the issue.
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  8. #8
    Registered User
    Join Date
    Jun 2011
    Location
    Nasik India
    Posts
    39

    Re: Command Action for alert

    @Raj - I am just including few commands from commandAction() . Currently am using more than 10 commands in command action. Please help me ASAP & let me know if u need anything more..Thank You...

    public void commandAction(Command command, Displayable displayable) {
    if (command == cmdExit) {
    exitMIDlet();
    }
    else if (command == cancelNo)
    { // some code w
    }
    else if (command == cancelYes)
    {
    exitMIDlet();

    }
    else if (command == downloadCancel)
    {

    Alert alert = new Alert("Are you Sure?","Want to Exit...",null,AlertType.WARNING);
    alert.setTimeout(Alert.FOREVER);

    //cancelYes & CancelNo Comands are globally declared.

    alert.addCommand(cancelYes);
    alert.addCommand(cancelNo);
    alert.setCommandListener(this);
    Displayable d = getDisplay().getCurrent();
    switchDisplayable(alert, d);

    }
    }

  9. #9
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Re: Command Action for alert

    Could you change and test this code and let me know the results

    Code:
    /*
     * CommandMidlet.java
     *
     * Created on August 19, 2011, 5:35 PM
     */
    
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    
    /**
     *
     * @author  rajiv.sharma
     * @version
     */
    public class CommandMidlet extends MIDlet implements CommandListener{
        
        Form f = new Form("Testing");
        Display d = null;
        
        Command c1 = new Command("label1", Command.OK,1);
        Command c2 = new Command("label12", Command.OK,1);
        Command c3 = new Command("label3", Command.OK,1);
        
        
        public CommandMidlet(){
            
        }
        public void startApp () {
            d = Display.getDisplay (this);
            f.addCommand (c1);
            f.addCommand (c2);
            f.addCommand (c3);
            f.setCommandListener (this);
            d.setCurrent (f);
            
        }
        
        public void pauseApp () {
        }
        
        public void destroyApp (boolean unconditional) {
        }
    
        public void commandAction (Command command, Displayable displayable) {
            if(command == c1){
                Alert alert = new Alert("Title","This is the alert",null,AlertType.ERROR);
                alert.addCommand (c2);
                alert.addCommand (c3);
                alert.setCommandListener (this);
                d.setCurrent (alert);
            } else if(command == c2){
                System.out.println("-------------c2");
            } else if(command == c3){
                System.out.println("-------------c3");
            }
        }
    
    }
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  10. #10
    Registered User
    Join Date
    Jun 2011
    Location
    Nasik India
    Posts
    39

    Re: Command Action for alert

    @ Raj - Thank you for snippet....I have tested it & its working fine.. ..but if I integrate same (exactly same) code in my project then its not working it gives same problem ....May be am missing something in my complex code..... I will review my code and try to find out the bug.... One more thing i would like to share with you, when I selects any one command of an alert then nothing will happen, but after that when I close the entire project then that commands automatically get invoked & "------------c3" is printed on console....
    Last edited by vishal.vpb; 2011-08-22 at 06:40.

  11. #11
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Re: Command Action for alert

    is there any running threads in your project in other class?
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  12. #12
    Registered User
    Join Date
    Jun 2011
    Location
    Nasik India
    Posts
    39

    Re: Command Action for alert

    Quote Originally Posted by raj_J2ME View Post
    is there any running threads in your project in other class?
    Yes ....am using thread in same class but in other function..

    am calling the function_2() from function_1().
    In function_1() am using thread.
    I want alert to be invoked with command from function_2()........

  13. #13
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Re: Command Action for alert

    Try to test the same without the threading call and revert
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

Similar Threads

  1. Gauge in Alert for unlimited time without Dismiss Command
    By sandeepkumar03 in forum Mobile Java General
    Replies: 4
    Last Post: 2010-03-04, 05:42
  2. How to use Center Button click for NEXT Command action in J2ME?
    By grishma48 in forum Mobile Java General
    Replies: 4
    Last Post: 2010-01-15, 11:44
  3. Replies: 4
    Last Post: 2008-06-27, 06:41
  4. Action after an Alert
    By bboissard in forum Mobile Java General
    Replies: 2
    Last Post: 2004-03-25, 13:46
  5. Command Listener / Command action
    By monkforte in forum Mobile Java General
    Replies: 4
    Last Post: 2004-01-17, 14:42

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×