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
Regular Contributor
Posts: 87
Registered: ‎07-07-2010
My Device: 8520
My Carrier: Student

Reboot not asked after deploy

[ Edited ]

Hi,

I've an application that run on startup, this is my descriptor

 

 

This is my main

 

public class MyApp extends UiApplication {
    public static void main(String[] args) {
        MyApp theApp = new MyApp();
        if (ApplicationManager.getApplicationManager().inStartup()) {
            theApp.addFileSystemListener(new MyFileSystemListener(theApp));
        }
        theApp.enterEventDispatcher();
    }

    public MyApp() {

        if (!ApplicationManager.getApplicationManager().inStartup()) {

              pushScreen(new MyScreen());

        }

    }

}

 

and this is MyFileSystemListener

 

public class MyFileSystemListener implements FileSystemListener {
    private MyApp instance;
    
    public MyFileSystemListener(MyApp instance) {
        super();
        this.instance = instance;
    }
    
    public void rootChanged(int state, String rootName) {
        if (state == ROOT_ADDED) {
            if (Util.isSDCardMounted()) {

                // The above function is a function written in my Util
                getInstance().removeFileSystemListener(this);
                
                try {
                    if (!DatabaseFactory.exists(URI.create(Constants.DB_FOLDER + Constants.DB_NAME))) {
                        // Se il DB non esiste si crea

                        // createDB is a function written in my DBUtil

                        DBUtil.getInstance().createDB();
                    }
                } catch (DatabaseIOException dioe) {
                    Util.logError("Errore durante DatabaseFactory.exists", dioe);
                } catch (DatabasePathException dpe) {
                    Util.logError("Errore durante DatabaseFactory.exists", dpe);
                } catch (MalformedURIException mue) {
                    Util.logError("Errore durante DatabaseFactory.exists", mue);
                }
                
                getInstance().pushScreen(new MyScreen());
            }
        } else if (state == ROOT_REMOVED) {
            
        }
    }

    public MyApp getInstance() {
        return instance;
    }

    public void setInstance(MyApp instance) {
        this.instance = instance;
    }
}

 

After deploy is not asked to reboot device, but if I don't reboot device I never enter in ApplicationManager.getApplicationManager.insStartup()... Can you tell me if there is something wrong in this code?

 

Thanks in advance.

 

Regards,

Gianni.

 

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Reboot not asked after deploy

The main code is run at deployment time - you should know that because you will see your screen.  So your logic to determine whether or not to add your FileListener is not correct, you need to change that.  You need to check whether or not you FileListener is removed during soft power down to - because if it is, you will need to implement to add it back in at powerUp, so have a look at the SystemListener and SystemListener2 classes. 

Regular Contributor
Posts: 87
Registered: ‎07-07-2010
My Device: 8520
My Carrier: Student

Re: Reboot not asked after deploy

Hi Peter,

my problem is that, at init, I have to register some listener (e.g. PimListener), and create DB, if it doesn't exists. DB is on SDCard, so I can't use SystemListener because at powerUp SDCard is not mounted. I use FileSystemListener because I need to know when SDCard is mounted. I didn't understand where is my error... Please, could you repeat me?

 

Thanks so much,

Gianni.

 

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Reboot not asked after deploy

You have the following code:

 

        if (ApplicationManager.getApplicationManager().inStartup()) {
            theApp.addFileSystemListener(new MyFileSystemListener(theApp));
        }

 

and then in MyFileSystemListener, you initiate your DB create and register your PIM listener. 

 

In the case when you have just instlalled, you can do this immediately. i.e.

 

        if (ApplicationManager.getApplicationManager().inStartup()) {
            theApp.addFileSystemListener(new MyFileSystemListener(theApp));
        } else {

            // check DB and register listener.
        }

 

Regardless of how you do it, you wll need to careful what a soft shutdown does to your listener - if it removes it (unlikely, but you need to test), then you will need to use SystemListener to make sure it is re-instated.  But that is a secondary concern, let us solve the startup one first. 

Regular Contributor
Posts: 87
Registered: ‎07-07-2010
My Device: 8520
My Carrier: Student

Re: Reboot not asked after deploy

[ Edited ]

My problem is that, at startup, I add a menu voice to Calendar's menu (by using ApplicationMenuItemRepository...). If I execute n times the initialization I have n voices in menu, but I need only one voice... May you tell me how test if that voice is present or not? This is my code:


MyMenu menu = new MyMenu();
        ApplicationMenuItemRepository.getInstance().addMenuItem(ApplicationMenuItemRepository.MENUITEM_CALENDAR, menu);

 

and this is MyMenu class


public class MyMenu extends ApplicationMenuItem {
    public MyMenu() {
        super(1000000);
    }
    
    public Object run(Object context) {
        // handle the action of our menu
        if (context == null) {
            return null;
        }
        try {
            UiApplication.getUiApplication().pushScreen(new MyScreen((BlackBerryEvent) context));
        } catch (Exception e) {
            System.err.println(e.getMessage());
        }
        return null;
    }

    public String toString() {
        // this is the label for our menu
        return Constants.Menu.MY_CONSTANT;
    }
}

 

Thanks a lot...

 

PS: a soft shutdown doesn't remove my PimListener...

 

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Reboot not asked after deploy

Isn't this a different problem to the one that you started the Thread with?  If you have a new question, please start a new Thread. 

 

The question has been asked before, search around.  The usual answer involves using RuntimeStore to hold an indication that the menu items has been added.  You will also need to implement SystemListener to repopulate after soft power off, since these menu items are removed during that process.  . 

 

If this Thread has been solved, can you mark it so?

Regular Contributor
Posts: 87
Registered: ‎07-07-2010
My Device: 8520
My Carrier: Student

Re: Reboot not asked after deploy

This isn't a different problem, because I wait for startUp to registerListener, add menu voice (only one time) and create DB (when SDCard is mounted). I choose this moment to do all things, and I bilieved this is the current way because menu voices and listener are not removed at soft shutdown, but I think to understand the problem...

 

I'm still a little bit confused so, before closing the thread, I'd like to take a few time and re-write a code, if it's not a problem...

 

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Reboot not asked after deploy

I don't think some Listeners are but I do think RuntimeStore and Menu items are removed over soft reset (e.g. when the user presses the poweroff icon).  Something to watch out for anyway.