BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 07-06-2007, 05:38 AM   #1 (permalink)
Thumbs Must Hurt
 
Join Date: May 2007
Location: Bulgaria
Model: none
PIN: N/A
Carrier: Mtel
Posts: 150
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Dialog as Thread?

Please Login to Remove!

I have the main thread and another more thread running with the main thread...I need a dialog in the main thread that should close itself when the other thread stopped...Do I need this dialog extends thread?...Cause when the dialog is not a thread and is in the main thread, the main thread is stopping where the dialog is set because it is waiting for my choice...I used Dialog.ask(....);....but it is modal...so i tried with new Dialog(...) object...but in this case i cannot show the dialog when i want....I am confused and don't have a clear idea...Can s.o. help me?
Offline  
Old 07-06-2007, 06:16 AM   #2 (permalink)
CrackBerry Addict
 
Join Date: Jun 2005
Location: Manchester, UK
Model: BOLD
Carrier: t-mobile
Posts: 714
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

have you tried popping the dialog from the background thread?

UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
UiApplication.getUiApplication().popScreen(UiAppli cation.getUiApplication().getActiveScreen());
}
});
__________________
new job doesn't allow a public profile - please do not contact this user with questions, you will not get a response. good luck!

Last edited by jfisher : 07-06-2007 at 06:18 AM.
Offline  
Old 07-06-2007, 06:19 AM   #3 (permalink)
New Member
 
Join Date: Apr 2006
Model: 8800
Carrier: vodafone
Posts: 8
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Example

I use this in the constructor of a MainScreen
Code:
_singleton=this;
 _timer=new Timer();
_timer.schedule(new TimerTask(){
                public void run(){
                    synchronized(UiApplication.getUiApplication().getEventLock()){
                        UiApplication.getUiApplication().popScreen(_singleton);
                    } 
                }
        },60000);
that makes the window close 1 minute after
Offline  
Old 07-06-2007, 06:44 AM   #4 (permalink)
Thumbs Must Hurt
 
Join Date: May 2007
Location: Bulgaria
Model: none
PIN: N/A
Carrier: Mtel
Posts: 150
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

well...

jfisher, i didn't tried this...now i have a code like this...and i don't know why the dialog is not pushed to the screen....

Dialog closeDialog = null;
if (!cancel && isRunning) {
closeDialog = new Dialog("synchronizing...", new String[] {"Cancel"},
new int[] {Dialog.CANCEL}, Dialog.CANCEL, Bitmap.getPredefinedBitmap(Bitmap.INFORMATION));
closeDialog.show();
closeDialog.setDialogClosedListener(this);
} else {
//isCancelled = true;
closeDialog.close();
}

This code is in the main thread...i have not tried to put the dialog in the background thread...but where in your posted code is the Dialog which i need...i can not understand this...
Offline  
Old 07-06-2007, 06:47 AM   #5 (permalink)
Thumbs Must Hurt
 
Join Date: May 2007
Location: Bulgaria
Model: none
PIN: N/A
Carrier: Mtel
Posts: 150
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Maybe you mean that this method getActiveScreen() is my Dialog...but i have a screen which is active at that time...i need to put a dialog above this active screen and hide it when the background thread stops
Offline  
Old 07-06-2007, 08:24 AM   #6 (permalink)
CrackBerry Addict
 
Join Date: Jun 2005
Location: Manchester, UK
Model: BOLD
Carrier: t-mobile
Posts: 714
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

The way i do this scenario is to set the thread going and then display a dialog akin to:

someThread sT = new someThread();
sT.start();
UiApplication.getUiApplication.pushScreen(myCustom Popup());
//or simply:
//Dialog.inform("Message");//or whatever you're using for your popup
//you could also use pushModalScreen to block

your dialog is now the topmost screen on the stack, your thread is doing whatever it's doing, when the thread has finished if you call the popScreen from the thread it'll remove the popup and if it's modal you can continue with your main thread.
__________________
new job doesn't allow a public profile - please do not contact this user with questions, you will not get a response. good luck!
Offline  
Old 07-06-2007, 09:04 AM   #7 (permalink)
Thumbs Must Hurt
 
Join Date: May 2007
Location: Bulgaria
Model: none
PIN: N/A
Carrier: Mtel
Posts: 150
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes you are right but my case is not that easy...It is not working like this..I have this piece of code:

private void sync() {
Sync sync = null;
ProgressStatus prog = new ProgressStatus();
boolean isCancelled = false;
synchronized (prog) {
if (!isRunning) {
isRunning = true;
isCancelled = false;
sync = new Sync(prog, dataBase, isCancelled, dataLimit, isRunning);
sync.start();
isRunning = sync.getIsRunning();
}
}
cancelDialog = new Dialog("synchronizing...", new String[] {"Cancel"},
new int[] {Dialog.CANCEL}, Dialog.CANCEL, Bitmap.getPredefinedBitmap(Bitmap.INFORMATION));
cancelDialog.setDialogClosedListener(this);
while (isRunning) {
try {
Thread.sleep(100L);
} catch (InterruptedException exception) {
exception.printStackTrace();
}
synchronized (prog) {
isRunning = sync.getIsRunning();
if (isCancelled) {
sync.setCancelled(isCancelled);
Status.show("Sync is cancelled");
}
}
if (!cancel && isRunning) {
//cancelDialog.show();
UiApplication.getUiApplication().pushScreen(cancel Dialog);
//add(cancelDialog);
} else {
cancelDialog.close();
isCancelled = true;
}
}
}

the sync object is my thread...this is happening when a button is clicked...on the device a screen is displayed...so i cannot see the cancelDialog (Dialog object) on the display...

Forget about this...I don't want to waste your time...I will handle with that somehow
Offline  
Closed Thread


Thread Tools

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





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