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: 237
Registered: ‎07-20-2010
My Device: Not Specified

Re: how many screens can I push in a new thread?

Alas, the button on the main screen approach worked but was not to the liking of the powers that be.  I'll need to pop open a little window like an alert dialog with a button in it telling people that the GPS system is still tring to get their  current location and with a button on it that takes them to the Location screen (where they can choose the method of setting their location (GPS, manually picking a city center or address)) and a second bttton a standard OK button which just dismisses the alert.

 

So When the app first loads up and gets the http connection and a little data from it, (after the splash screen fades out as that work is done while the splash is displayed) the mainscreen will display, and on top of it I will display my alert if and only if the app is still waiting for the GPS to find the location.

 

I guess I'll need a background thread running that will monitor for the GPS success and fire up the alert if the GPS is still waiting.   I haven't worked with threads much so I'm not sure what the best way to do that is.  Maybe in the constructor of my app I'll create an inner class alertThread and fire it up like so:

 

openLocationThread firstloc =  new openLocationThread();
firstloc.start();

 

then in the start method I'll have a while loop checking for the GPS connection like so:

 

public class openLocationThread extends Thread {
private boolean once = true; 
//i want this to only pop up the alert once 
//in the lifetime of the app
public void run(){
while (GPS not finished){
try {
Thread.sleep(500);
}catch {(InterruptedException e) {
//do nothing
}
if (once &&

 

(GPS not finished)

 

){
UiApplication.getUiApplication().invokeAndWait(new Runnable(){
public void run(){
if (locscr != null){
once = false;
if (locscr.isDisplayed()){
try{ popScreen(locscr);
}catch(IllegalArgumentException e){}
}
popalert();
/* locscr.getMessageField().setText("Your cell site location could not be determined or your phone is improperly connected to the mobile network. Please set your location manually or try again to use GPS/Cell.") ;
*/
//pushScreen(locscr); //locscr.invalidate(); // } } }); } } } }

Will that basic approach work and how will I kil the thread after if does its job?

 

BTW, why can't I see my cursor on this page ?  it makes it hard to format my post.