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
Posts: 264
Registered: ‎10-05-2010
My Device: Not Specified
Accepted Solution

Two screens running concurrently and in the background.

[ Edited ]

I am trying to have two screens running concurrently in the background. Both have timers for different events and I would like the user to switch between them on the menu to check their progress. I would also like the app with both screens to be able to run in the background when closed.

 

I got them both running in the background by overriding the Screen's onClose with:

 

 

public boolean onClose() {
	UiApplication theApp = UiApplication.getUiApplication();
	theApp.requestBackground();
	return true;
}

 

 

That works great. But how to I do the same to flip back and forth between screens within the application?

 

The functionality I am looking for is similar to the RIM Stopwatch application. You can run the Stopwatch and the Timer concurrently. You flip back and forth between them in the menu...

 

Thanks

 

 

Developer
Posts: 220
Registered: ‎09-09-2008
My Device: Bold 9780
My Carrier: Telstra AU

Re: Two screens running concurrently and in the background.

You have 2 threads running in the background as the UI is only used for the display.

 

When the user bring the application back to foreground you need to handle what you going to display ie bring the correct screen to the foreground. The foreground can be handled in the active method of the Application.

 

If you want a menu item to appear out side your own application please check the Application Menu Item Repository.

 

I hope this get you started if you need more help of any of the points above please let me know.

-----------

Follow me on twitter: twitter.com/paul.haenel

If your issue is resolved, please mark this thread as solved.

Set the "Solution" mark on the post which contains the answer to your question.
Developer
Posts: 264
Registered: ‎10-05-2010
My Device: Not Specified

Re: Two screens running concurrently and in the background.

Sorry but I'm still not getting it...

 

I have the application working in the background now. I have say Screen1 and Screen2. Both have timers on them for different events. If I start the timer on Screen1 and exit the applicateion, it comes back up as I would expect and has not lost a tick. I can do the same for the timer on Screen2 and that works too. 

 

However, I would like to start the timer on Screen1, then navigate via the menu to Screen2 and start that timer also. I would like to be able to flip between them while they both continue normally. I would also like to be able to send the application to the background and bring both screens back without interrupting the timers.

 

My menu code looks like this:

 

private MenuItem _stopwatchItem = new MenuItem("Stopwatch", 110, 100) {
	public void run() {
		UiApplication theApp = UiApplication.getUiApplication();
		//theApp.popScreen(theApp.getActiveScreen());
		theApp.pushScreen(new StopwatchScreen());
	}
};
private MenuItem _countdownItem = new MenuItem("Countdown", 110, 100) {
	public void run() {
		UiApplication theApp = UiApplication.getUiApplication();
		//theApp.popScreen(theApp.getActiveScreen());
		theApp.pushScreen(new CountdownScreen());
	}
};

I've tried a few things but I still don't understand the mechanism for keeping both screens alive. I can pop one on top but it resets everything. I need to pop it on top of the stack while maintaining the data and tasks running in it.

 

Thanks

 

Developer
Posts: 220
Registered: ‎09-09-2008
My Device: Bold 9780
My Carrier: Telstra AU

Re: Two screens running concurrently and in the background.

When you refer to the screen i assume u mean the graphical interface. You can create the interface at the beginning ie launch of the application then you should use those screen instances to bring them to the front of the stack ( visible to the user ).

 

I think some pseudo code would be helpful as im not 100% of the structure of you code and what exactly you trying to do.

 

As from the code snap shot above you create a screen instance every time so i gather you rather want to just bring the screen to the front from the stack.

 

You also should run the timers in a different thread not in the UI thread. Maybe think of it this way you have one class which manages the two screens and holds the instance of the timer so you can access them and build the ui from it.

 

Hope that makes it a bit clearer.

-----------

Follow me on twitter: twitter.com/paul.haenel

If your issue is resolved, please mark this thread as solved.

Set the "Solution" mark on the post which contains the answer to your question.
Developer
Posts: 264
Registered: ‎10-05-2010
My Device: Not Specified

Re: Two screens running concurrently and in the background.

I think that did it. I moved the new Screen creation  as well as the new Timer creation to the Application class itself. Then I declared them all static so I can see them from the other Screens. That seemed to do it...

 

More like this...

 

public class StopwatchApplication extends UiApplication {
	
	public static CountdownScreen countdownScreen;
	public static StopwatchScreen stopwatchScreen;
	
	public static LapTimer timeKeeper1 = new LapTimer();  //Object to keep track of time
	public static CountTimer countKeeper1 = new CountTimer();  //Object to keep track of time
	
	public static void main(String[] args) {
		StopwatchApplication theApp = new StopwatchApplication();
		theApp.enterEventDispatcher();	
	}
	public StopwatchApplication() {
		countdownScreen = new CountdownScreen(); 
		stopwatchScreen = new StopwatchScreen();
		pushScreen(stopwatchScreen);
	}
}

 

 

 

Thanks