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

Posts: 68
Registered: ‎10-26-2008
My Device: Not Specified

Problems running background App



I'm having issues running my app in the background. Here's what I want to do:

1) kick off a non-gui app when the device starts to collect and update GPS location in the background

2) when the app is started from the ribbon, create the GUI and use the updated GPS data from the background app


I coded something up that works fine for the GUI side of things, but  whenever I try to create an object in my background thread, I get a slew of NullPointer, Java Error, InvalidArgument Exception, etc.It seems that if I try to create an instance of my GPS class, or even if I just try to grab a LocationProvider object inside main() (even if I create a seperate thread to do it) I will get the JVM error, Exceptions and other goodies. I followed the article on setting alternate entry points and I think that is working fine. 


Is there a reason why I cannot grab LocationProvider instances from main() or a thread created in main?


Here is my code:


public class startClass extends UiApplication {

    public static final long GPS_APP = 0xd9e88ec2f48beb7L; 
    public static void main(String [] args){
        boolean launchGUIApp = false;
        if(args != null && args.length > 0){
            for (int i=0; i<args.length; ++i){
                    launchGUIApp = true;
                    i = args.length+1;

                RuntimeStore store = RuntimeStore.getRuntimeStore();
                GPS G =  (GPS)store.get(GPS_APP);
                startClass sc = new startClass(G);
            }catch (Exception e){
                System.out.print("ERROR WHILE LAUNCHING GUI : e.type = " + e.getClass() + "  e.msg=" + e.getMessage());



           GPS G = new GPS();
            RuntimeStore store = RuntimeStore.getRuntimeStore();
            store.put(GPS_APP, G);
    public startClass(GPS _G){
            pushScreen(new mainScreen(_G));

BlackBerry Development Advisor
Posts: 15,876
Registered: ‎07-09-2008
My Device: BlackBerry PRIV
My Carrier: Bell

Re: Problems running background App

Depending on what the application is doing, it may need to call enterEventDispatcher when it is initially started.  You can then call requestBackground to move the application into the background.  The icon entry point for your application could then call requestForeground to display your GUI.


You can also override the Application.acceptsForeground method to prevent the application from appearing in the task switcher when it is running in the background.

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.