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
Developer
mlisaoverdrive
Posts: 179
Registered: ‎09-11-2009
My Device: Not Specified

Very Bizarre Application Issue

My app, which starts from a browser ApplicationMenuItem, and which was working correctly has suddently stopped doing so.  The main problem is that the ApplicationMenuItem no longer appears in the browser menu as designed.

 

The last feature I was trying to implement was hiding the application from the Application Switcher, by integrating the code found in this article:  http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800505/800256/....

 

When I couldn't get it to work, I backed out of all of my changes and reimplemented the original code, which is as follows

Code for the main():

 

 

public class addToReadingList extends UiApplication
{
    
      /**
     * @param args the command line arguments
     */

    public void main(String[] args)
    {
           addToReadingList atrl = new addToReadingList();
           atrl.enterEventDispatcher();
    }
 addToReadingList()
    {
           browserMenuItem bmi = new browserMenuItem(5);
           ApplicationMenuItemRepository repository = ApplicationMenuItemRepository.getInstance();
           repository.addMenuItem(ApplicationMenuItemRepository.MENUITEM_BROWSER, bmi);
    }
    }

 

Code for the ApplicationMenuItem class:

 

 

public class browserMenuItem extends ApplicationMenuItem
{
    // credentialsScreen cs;
    StringBuffer cr;
    int rc;
    // private boolean iconStatus;

    //constructor for ApplicationMenuItem
    browserMenuItem(int order)
    {
        super(order);
    }

    public String toString()
    {
        return "add to reading list";
    }

    public Object run(Object context)
    {
        try
        {
        if (context != null)
        {
                threadReadItLater tril = new threadReadItLater(context);
                Thread t = new Thread(tril);
                // addToReadingList atrl = new addToReadingList();
                // atrl.setAcceptsForeground(false);
                t.start();
        }
        }catch(Exception ex)
        {
            //System.out.println("Handling context error code: " + ex.toString());
        }
        return null;
      }
    
}

 

 

I've run clean.bat on the simulator twice, I've done a clean and rebuild on the code (I'm using NetBeans) and I still have the same problem:  The ApplicationMenuItem does not appear in the browser menu.

 

Any help would be greatly appreciated.  I'm completely baffled.

 

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

Re: Very Bizarre Application Issue

Has your main actually been invoked?

 

Normally you would do this by marking the application as auto-start.

 

In this case, I suspect there is an icon, so you could do it by pressing the icon.

 

System.out.println would show up in the debugging window so you could see if your code was being executed.  Alternatively do some thing really silly in there that will throw a null pointer exception or similar and see if you get an exception.

Developer
mlisaoverdrive
Posts: 179
Registered: ‎09-11-2009
My Device: Not Specified

Re: Very Bizarre Application Issue

 


peter_strange wrote:

Has your main actually been invoked?

 

Normally you would do this by marking the application as auto-start.

 

In this case, I suspect there is an icon, so you could do it by pressing the icon.

 

System.out.println would show up in the debugging window so you could see if your code was being executed.  Alternatively do some thing really silly in there that will throw a null pointer exception or similar and see if you get an exception.


 

 

I figured out the problem...there was a warning in the output window about the public void main(String[] args), something about it not being static.  I forgot that I'd removed the modifier 'static' from main() method earlier when I was trying to fit the
Application Switcher hiding code in.  Putting the 'static' modifier back in fixed the problem.

 

Now, back to figuring out how to hide the app from the Application Switcher.

 

Too bad there's no embarassed emoticon...

Developer
mlisaoverdrive
Posts: 179
Registered: ‎09-11-2009
My Device: Not Specified

Re: Very Bizarre Application Issue

 


mlisaoverdrive wrote:

 


peter_strange wrote:

Has your main actually been invoked?

 

Normally you would do this by marking the application as auto-start.

 

In this case, I suspect there is an icon, so you could do it by pressing the icon.

 

System.out.println would show up in the debugging window so you could see if your code was being executed.  Alternatively do some thing really silly in there that will throw a null pointer exception or similar and see if you get an exception


Now, back to figuring out how to hide the app from the Application Switcher.

 


 

 

Figured it out.  For anyone else struggling with this, I took the last part of the code from the "How To - Prevent UiApplication from being listed in the application switcher" and added the setAcceptsForeground method to the application's constructor...which is basically a menu item.

 

Looks like this:

 

 

public class addToReadingList extends UiApplication
{
     addToReadingList()
    {
           browserMenuItem bmi = new browserMenuItem(10);
           ApplicationMenuItemRepository repository = ApplicationMenuItemRepository.getInstance();
           repository.addMenuItem(ApplicationMenuItemRepository.MENUITEM_BROWSER, bmi);
           setAcceptsForeground(false);
    }
    
      /**
     * @param args the command line arguments
     */

    public static void main(String[] args)
    {
           addToReadingList atrl = new addToReadingList();
           atrl.enterEventDispatcher();
    }
    private boolean _acceptsForeground;

 //This is the method to override
    protected boolean acceptsForeground() {
        return _acceptsForeground;
    }
    //This method sets whether the application will allow itself
    //to foreground
    protected void setAcceptsForeground(boolean bool)
    {
        _acceptsForeground = bool;
    }
    }

 

 

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

Re: Very Bizarre Application Issue

In this case, you do not actually need to create a UiApplication, or an Application at all.  All your processing runs under the Browser application, so all you actually have to have in your main() method is the following:

 

    public void main(String[] args)
    {
           browserMenuItem bmi = new browserMenuItem(5);
           ApplicationMenuItemRepository repository = ApplicationMenuItemRepository.getInstance();
           repository.addMenuItem(ApplicationMenuItemRepository.MENUITEM_BROWSER, bmi);
    }

 

mark this as a System module so you don't get an icon and auto run at startup so that the menu item is added, and you are done.

 

So no need to suppress the Application switch icon.