BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 06-11-2008, 02:13 PM   #1
EmilieL
Thumbs Must Hurt
 
Join Date: Apr 2008
Model: 7100T
PIN: N/A
Carrier: idk
Posts: 84
Default PushScreen from background thread

Please Login to Remove!

Hi everyone!
I'm trying to push a screen from a background thread but nothing seems to work.

I have a thread working in the background.
When certain conditions are met, I want the mainscreen to be pushed...

I've tried many things such as the invokelater method, calling the event dispatcher, requesting foreground, etc, etc, etc...
nothing seems to work...

any ideas?
__________________
Stop telling me what it can do...
Show me how to make it do it!!!!
Offline  
Old 06-11-2008, 03:36 PM   #2
CELITE
Thumbs Must Hurt
 
Join Date: Dec 2005
Model: 8310
Carrier: Rogers
Posts: 138
Default

Show us the code you use to push it. By background thread you mean your app is listening in the background for a global event?
Offline  
Old 06-12-2008, 08:36 AM   #3
EmilieL
Thumbs Must Hurt
 
Join Date: Apr 2008
Model: 7100T
PIN: N/A
Carrier: idk
Posts: 84
Default

It's a background thread, lauched at the startup of the blackberry.
It listens for incoming messages from a server.
When the server sends a specific message, I want the mainscreen of the app to be pushed.
I have no problems sending data to the screen but I can't seem to be able to push it...

Here's what I tried :

Code:
mMainMenu = MainMenu.getMainMenuInstance();    
    net.rim.device.api.ui.UiApplication.getUiApplication().pushScreen(mMainMenu);

mMainMenu.PlayAlarm();
Exception thrown: @1EDC4000 java.lang.IllegalStateException

Code:
TempDisplay instance = new TempDisplay();
instance.enterEventDispatcher();
mMainMenu = MainMenu.getMainMenuInstance();
mMainMenu.PlayAlarm();
java.lang.RuntimeException: application already running in this process

Code:
mMainMenu = MainMenu.createMainMenuInstance();
            mMainMenu.init();
            net.rim.device.api.ui.UiApplication.getUiApplication().pushScreen(mMainMenu);
            mMainMenu.PlayAlarm();
This one doesn't throw exceptions but nothing happens..

Any other ideas?
__________________
Stop telling me what it can do...
Show me how to make it do it!!!!
Offline  
Old 06-12-2008, 09:01 AM   #4
simon.hain
CrackBerry Addict
 
Join Date: Apr 2005
Location: hamburg, germany
Model: 8900
Carrier: o2
Posts: 838
Default

and where is your mentioned invokelater/synchronization on the event thread?
__________________
java developer, Devinto, hamburg/germany
Offline  
Old 06-12-2008, 09:29 AM   #5
EmilieL
Thumbs Must Hurt
 
Join Date: Apr 2008
Model: 7100T
PIN: N/A
Carrier: idk
Posts: 84
Default

sorry.. forgot that one..
I tried so many things...

it also throws an illegalstate exception

Code:
UiApplication.getUiApplication().invokeLater (new Runnable() 
            {
                public void run()
                {
                    //Code here
                }
             });
__________________
Stop telling me what it can do...
Show me how to make it do it!!!!
Offline  
Old 06-12-2008, 10:43 AM   #6
EmilieL
Thumbs Must Hurt
 
Join Date: Apr 2008
Model: 7100T
PIN: N/A
Carrier: idk
Posts: 84
Default

There...
I created a new project with just the code I need (didn't want to bother you with all of the code)

So what would I need to do to push the screen (if it's not already displayed)
Whatever I try, I always end up with a illegalstate exception :(

Code:
class TestPushScreen extends net.rim.device.api.ui.UiApplication
{
    public static void main(String[] args)
    {
        if(args != null && args.length > 0 && args[0].equals("gui"))
        {
            TestPushScreen instance = new TestPushScreen();
            instance.enterEventDispatcher();
        }
        else
        {
            mBackgroundThread = new BackgroundThread();          
            if(mBackgroundThread == null)
            {
                //impossible to create thread... so exit
                System.exit(-1);
            }
            else
            {
                try
                {
                    Thread.sleep(2000);
                    mBackgroundThread.start();
                }
                catch(Throwable ie)
                {
                    
                }
            }
        }
    }
    TestPushScreen() 
    {    
        mMainMenu = MainMenu.createMainMenuInstance();
        pushScreen(mMainMenu);
    }
    
    public static MainMenu mMainMenu;
    public static BackgroundThread mBackgroundThread;
Code:
/*
 * MainMenu.java
 *
 * © <your company here>, 2003-2005
 * Confidential and proprietary.
 */

/**
 * 
 */
 import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.system.*;
import javax.microedition.media.*;
import javax.microedition.io.*;
import java.io.*;
import javax.microedition.rms.*;


class MainMenu extends MainScreen
{
    MainMenu() 
    {    
        mTest = new BasicEditField("Hello","");
        add(mTest);
    }
    
    public static MainMenu createMainMenuInstance()
    {
        //Ensure this is a singleton instance.
        
        try
        {
        
            //Open the RuntimeStore.
            RuntimeStore store = RuntimeStore.getRuntimeStore();
            //Obtain the reference of MainMenu.
            Object obj = store.get(RTSID_MY_APP);
        
            if (obj == null)
            {
                //Store a reference to this instance in the RuntimeStore.
                store.put(RTSID_MY_APP, new MainMenu());
            
                return (MainMenu)store.get(RTSID_MY_APP);
            } 
            else
            {
                return (MainMenu)obj;
            }
        }
        catch(ControlledAccessException e)
        {
            System.err.println(e.toString());
            return null;
        }
        catch(Throwable e)
        {
            e.printStackTrace();
            return null;
        }    
    }
    public static MainMenu getMainMenuInstance()
    {
        //Ensure this is a singleton instance.
        
        try
        {
            //Open the RuntimeStore.
            RuntimeStore store = RuntimeStore.getRuntimeStore();
            //Obtain the reference of MainMenu.
            Object obj = store.get(RTSID_MY_APP);
        
            if (obj == null)
            {            
                return null;
            } 
            else
            {
                return (MainMenu)obj;
            }
        }        
        catch(ControlledAccessException e)
        {
            System.err.println(e.toString());
            return null;
        }
        catch(Throwable e)
        {
            e.printStackTrace();
            return null;
        }                           
    }
    
    public static final long RTSID_MY_APP = 0x33abf322367f9019L;
    BasicEditField mTest;
}
Code:
/*
 * BackgroundThread.java
 *
 * © <your company here>, 2003-2005
 * Confidential and proprietary.
 */

/**
 * 
 */

class BackgroundThread extends Thread
{
    BackgroundThread() 
    {    
        
    }
    
    public void run()
    {
        while(true)
        {
            try
            {
                //Code to push screen if not already pushed here
                Thread.sleep(5000);
            }
            catch(Throwable ex)
            {
            }
        }
    }
}

Mmmm...
I was able to get the instance of my app and then call the pushScreen...
no error but the screen isn't displayed.
when the app tries to push it again after 5 seconds, I get a runtime error saying the screen is already pushed...
If it IS pushed, how come I don't seen it?

-- edit
I was able to display the screen.
I forgot to call "requestforeground"

Now, the problem is that after the screen is displayed, the thread stops running.
So it doesn't check for futur calls of pushscreen...
I want the thread to still run in the background, even if the screen is already displayed.
It WILL result into a runtime error, but I don't mind.. I just catch it and do nothing with it..
any ideas?
__________________
Stop telling me what it can do...
Show me how to make it do it!!!!

Last edited by EmilieL; 06-12-2008 at 12:38 PM..
Offline  
Old 11-18-2008, 12:41 AM   #7
dinu_hasith
New Member
 
Join Date: Nov 2008
Location: Colombo
Model: 8300
PIN: N/A
Carrier: Dialog
Posts: 5
Default

Quote:
Originally Posted by EmilieL View Post
There...
I created a new project with just the code I need (didn't want to bother you with all of the code)

So what would I need to do to push the screen (if it's not already displayed)
Whatever I try, I always end up with a illegalstate exception :(

Code:
class TestPushScreen extends net.rim.device.api.ui.UiApplication
{
    public static void main(String[] args)
    {
        if(args != null && args.length > 0 && args[0].equals("gui"))
        {
            TestPushScreen instance = new TestPushScreen();
            instance.enterEventDispatcher();
        }
        else
        {
            mBackgroundThread = new BackgroundThread();          
            if(mBackgroundThread == null)
            {
                //impossible to create thread... so exit
                System.exit(-1);
            }
            else
            {
                try
                {
                    Thread.sleep(2000);
                    mBackgroundThread.start();
                }
                catch(Throwable ie)
                {
                    
                }
            }
        }
    }
    TestPushScreen() 
    {    
        mMainMenu = MainMenu.createMainMenuInstance();
        pushScreen(mMainMenu);
    }
    
    public static MainMenu mMainMenu;
    public static BackgroundThread mBackgroundThread;
Code:
/*
 * MainMenu.java
 *
 * © <your company here>, 2003-2005
 * Confidential and proprietary.
 */

/**
 * 
 */
 import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.system.*;
import javax.microedition.media.*;
import javax.microedition.io.*;
import java.io.*;
import javax.microedition.rms.*;


class MainMenu extends MainScreen
{
    MainMenu() 
    {    
        mTest = new BasicEditField("Hello","");
        add(mTest);
    }
    
    public static MainMenu createMainMenuInstance()
    {
        //Ensure this is a singleton instance.
        
        try
        {
        
            //Open the RuntimeStore.
            RuntimeStore store = RuntimeStore.getRuntimeStore();
            //Obtain the reference of MainMenu.
            Object obj = store.get(RTSID_MY_APP);
        
            if (obj == null)
            {
                //Store a reference to this instance in the RuntimeStore.
                store.put(RTSID_MY_APP, new MainMenu());
            
                return (MainMenu)store.get(RTSID_MY_APP);
            } 
            else
            {
                return (MainMenu)obj;
            }
        }
        catch(ControlledAccessException e)
        {
            System.err.println(e.toString());
            return null;
        }
        catch(Throwable e)
        {
            e.printStackTrace();
            return null;
        }    
    }
    public static MainMenu getMainMenuInstance()
    {
        //Ensure this is a singleton instance.
        
        try
        {
            //Open the RuntimeStore.
            RuntimeStore store = RuntimeStore.getRuntimeStore();
            //Obtain the reference of MainMenu.
            Object obj = store.get(RTSID_MY_APP);
        
            if (obj == null)
            {            
                return null;
            } 
            else
            {
                return (MainMenu)obj;
            }
        }        
        catch(ControlledAccessException e)
        {
            System.err.println(e.toString());
            return null;
        }
        catch(Throwable e)
        {
            e.printStackTrace();
            return null;
        }                           
    }
    
    public static final long RTSID_MY_APP = 0x33abf322367f9019L;
    BasicEditField mTest;
}
Code:
/*
 * BackgroundThread.java
 *
 * © <your company here>, 2003-2005
 * Confidential and proprietary.
 */

/**
 * 
 */

class BackgroundThread extends Thread
{
    BackgroundThread() 
    {    
        
    }
    
    public void run()
    {
        while(true)
        {
            try
            {
                //Code to push screen if not already pushed here
                Thread.sleep(5000);
            }
            catch(Throwable ex)
            {
            }
        }
    }
}

Mmmm...
I was able to get the instance of my app and then call the pushScreen...
no error but the screen isn't displayed.
when the app tries to push it again after 5 seconds, I get a runtime error saying the screen is already pushed...
If it IS pushed, how come I don't seen it?

-- edit
I was able to display the screen.
I forgot to call "requestforeground"

Now, the problem is that after the screen is displayed, the thread stops running.
So it doesn't check for futur calls of pushscreen...
I want the thread to still run in the background, even if the screen is already displayed.
It WILL result into a runtime error, but I don't mind.. I just catch it and do nothing with it..
any ideas?
hi EmilieL,
how did you get the instance of your app and call pushScreen in the background thread?

i have to do exactly what you have done, but I have no idea how to push a screen to display the received message.
Offline  
Old 11-18-2008, 04:42 AM   #8
simon.hain
CrackBerry Addict
 
Join Date: Apr 2005
Location: hamburg, germany
Model: 8900
Carrier: o2
Posts: 838
Default

try Ui.getUiEngine, eventually in conjunction with pushglobalscreen.
__________________
java developer, Devinto, hamburg/germany
Offline  
Old 04-22-2009, 01:40 AM   #9
aksudhakar2002
New Member
 
Join Date: Jan 2009
Location: India
Model: 9000
PIN: N/A
Carrier: airtel
Posts: 3
Default

Hi,
I m new to Blackberry. can u just help me.. My Quest is ... using pushGlobalScreen() method for UiApplication i displayed popupscreen from mainscreen , now when i submit button from popupscreen , to show next screen (homepagescreen) using pushGlobalScreen() method.. i got homepagescreen . BUT THE POPUPSCREEN DOESNOT DISAPPEAR..
can u just help me.. any ways to solve it..
Offline  
Old 06-08-2009, 06:06 PM   #10
rak.koul@gmail.com
New Member
 
Join Date: May 2009
Model: 9000
PIN: N/A
Carrier: att
Posts: 5
Default

Simon.hain, you are the man......gotcha.... Ui.getUiEngine().pushScreen( ); is the trick,
But How did you ever figure tht out?
Offline  
Closed Thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


1pcs used TSXMFPP128K Memory Card picture

1pcs used TSXMFPP128K Memory Card

$175.00



HP / Agilent 85620A Mass Memory Module - Revision C picture

HP / Agilent 85620A Mass Memory Module - Revision C

$42.89



Desktop Memory Case Tray Case for PC DDR DRAM RAM DIMM Modules - 2 fits 100 New picture

Desktop Memory Case Tray Case for PC DDR DRAM RAM DIMM Modules - 2 fits 100 New

$20.50



Memory Blister Pack Box for DDR DIMM Module Anti Static - Lot of 6 18 35 100 200 picture

Memory Blister Pack Box for DDR DIMM Module Anti Static - Lot of 6 18 35 100 200

$32.95



NEW Mitsubishi A1SNMCA-8KE Memory Cassette picture

NEW Mitsubishi A1SNMCA-8KE Memory Cassette

$151.62



CORSTAT INTEGRATED CIRCUIT EXPANDED MEMORY DIP REV. A SER. B 2711-NM3 picture

CORSTAT INTEGRATED CIRCUIT EXPANDED MEMORY DIP REV. A SER. B 2711-NM3

$174.95







Copyright © 2004-2016 BlackBerryForums.com.
The names RIM © and BlackBerry © are registered Trademarks of BlackBerry Inc.