BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 11-24-2008, 07:42 AM   #1
sickned
Knows Where the Search Button Is
 
Join Date: Oct 2008
Model: 7100T
PIN: N/A
Carrier: Unknow
Posts: 42
Default Initialize the main screen and a web service call.

Please Login to Remove!

Hi,

I have to do the next in my application:

- At the start, do a web service call, that returns some data. If the connection fails, I have to show a message at the screen.

I've tried everything, but the enterEventDispatcher method (it paints all) doesnt return.

How can I do it? Where can I call the web service call, once the screen is displayed?

Thanks in advance.

Last edited by sickned; 11-24-2008 at 07:43 AM..
Offline  
Old 11-24-2008, 08:04 AM   #2
Ivanov
Talking BlackBerry Encyclopedia
 
Join Date: Apr 2008
Location: Germany, BW
Model: -
PIN: N/A
Carrier: -
Posts: 310
Default

enterEventDispatcher never returns, otherwise your application will be closed.

Your WS call has to be done in a separate Thread, which can be either created and started in the screen's constructor or in your UiApplication's constructor before or after pushing your screen
__________________
Blessed is the end user who expects nothing, for he/she will not be disappointed. (Franklin's Rule)
Offline  
Old 11-24-2008, 09:20 AM   #3
sickned
Knows Where the Search Button Is
 
Join Date: Oct 2008
Model: 7100T
PIN: N/A
Carrier: Unknow
Posts: 42
Default

Quote:
Originally Posted by Ivanov View Post
enterEventDispatcher never returns, otherwise your application will be closed.

Your WS call has to be done in a separate Thread, which can be either created and started in the screen's constructor or in your UiApplication's constructor before or after pushing your screen
Thanks Ivanov. Can you post some sample code, please?

Another issue is the data from the WS has to be disponible for the UIApplication. How connect two threads?

Thanks in advance.
Offline  
Old 11-24-2008, 09:52 AM   #4
sickned
Knows Where the Search Button Is
 
Join Date: Oct 2008
Model: 7100T
PIN: N/A
Carrier: Unknow
Posts: 42
Default

And another question. If I do the WS call in one thread and I get an exception, how can I send this to my app?

Thanks.
Offline  
Old 11-24-2008, 09:53 AM   #5
Ivanov
Talking BlackBerry Encyclopedia
 
Join Date: Apr 2008
Location: Germany, BW
Model: -
PIN: N/A
Carrier: -
Posts: 310
Default

for WS call examples look here in forum for kSOAP2 if you're using it to call your WS.
For creating Threads refer to RIM's API javadoc

I prefer to use callbacks to inform a listener about new information. Search for a forum thread conserning it
__________________
Blessed is the end user who expects nothing, for he/she will not be disappointed. (Franklin's Rule)
Offline  
Old 11-24-2008, 09:56 AM   #6
Ivanov
Talking BlackBerry Encyclopedia
 
Join Date: Apr 2008
Location: Germany, BW
Model: -
PIN: N/A
Carrier: -
Posts: 310
Default

Quote:
Originally Posted by sickned View Post
And another question. If I do the WS call in one thread and I get an exception, how can I send this to my app?

Thanks.
If you only want to show a popup message you can use global screens. Otherwise use callbacks as mentioned above
__________________
Blessed is the end user who expects nothing, for he/she will not be disappointed. (Franklin's Rule)
Offline  
Old 11-24-2008, 10:38 AM   #7
sickned
Knows Where the Search Button Is
 
Join Date: Oct 2008
Model: 7100T
PIN: N/A
Carrier: Unknow
Posts: 42
Default

Thanks Ivanov.

I've tried to use callbacks, but when I call the new Thread (who calls WS), the principal thread stay suspended or something.

I'll show you some code:

Code:
public class InicioThread extends Thread{
	
	PretiumController controller;
	InicioScreen screen;
	
	public InicioThread(PretiumController controller, InicioScreen screen){
		this.controller = controller;
		this.screen= screen;
	}
	
	public void run() {
		try {
			sleep(1000);			
			controller.inicializarApp(); //THIS CALLS THE WS
			screen.inicializarAplicación();
		} catch (Exception e) {
			screen.informarExcepción(e.getMessage());
		}
		
	}
	
}


public class InicioScreen extends MainScreen {
			
	PretiumController  controller;
	
	
	public InicioScreen(PretiumController controller){
		this.controller = controller;
		
		InicioLabelField inicio = new InicioLabelField(controller, "Iniciando aplicación...");
		
		add(inicio);	
		
		
		

	}
	
	
	
	public  void inicializarAplicación(){
		
			try{			
				UiApplication.getUiApplication().pushScreen(new SeleccionClienteScreen(controller));
				
			}catch(Exception e){
				Dialog.inform(e.getMessage());
			}
			
		
	}
	
	public void lanzarThread(){
		InicioThread t = new InicioThread(controller, this);
		t.run();
	}
	
	public void informarExcepción(String mensaje){
		Dialog.inform(mensaje);
	}


}

public class PretiumMain extends UiApplication{

	public static void main(String[] args) {
		PretiumMain theApp = new PretiumMain();		
		theApp.enterEventDispatcher();	
		
	}

	public PretiumMain() {

			PretiumController controller = new PretiumController();
			
			InicioScreen inicio = new InicioScreen(controller);
			
			UiApplication.getUiApplication().pushScreen(inicio);
			
			inicio.lanzarThread();
			
			
	
	}
}
What Im doing wrong?

Last edited by sickned; 11-24-2008 at 10:39 AM..
Offline  
Old 11-24-2008, 10:52 AM   #8
Ivanov
Talking BlackBerry Encyclopedia
 
Join Date: Apr 2008
Location: Germany, BW
Model: -
PIN: N/A
Carrier: -
Posts: 310
Default

Code:
		InicioThread t = new InicioThread(controller, this);
		t.run();
Threads are starting when calling start() otherwise run() is executed in your current class content.
__________________
Blessed is the end user who expects nothing, for he/she will not be disappointed. (Franklin's Rule)
Offline  
Old 11-24-2008, 11:06 AM   #9
sickned
Knows Where the Search Button Is
 
Join Date: Oct 2008
Model: 7100T
PIN: N/A
Carrier: Unknow
Posts: 42
Default

I've modified the code:

Code:
public class PretiumMain extends UiApplication{
	

	
	public static void main(String[] args) {
		PretiumMain theApp = new PretiumMain();			
		theApp.enterEventDispatcher();	
		
	}

	public PretiumMain() {

			PretiumController controller = new PretiumController();
			
			InicioScreen inicio = new InicioScreen(controller);

			UiApplication.getUiApplication().pushScreen(inicio);

	
	}

}

public class InicioThread extends Thread{
	
	PretiumController controller;
	InicioScreen pantalla;
	
	public InicioThread(PretiumController controller, InicioScreen pantalla){
		this.controller = controller;
		this.pantalla = pantalla;
		this.setPriority(1);
	}
	
	public void run() {
		try {
			sleep(2000);			
			controller.inicializarApp();
			pantalla.inicializarAplicación();
		} catch (Exception e) {
			pantalla.informarExcepción(e.getMessage());
		}
		
	}
	
}

public class InicioScreen extends MainScreen {
			
	PretiumController  controller;
	
	
	public InicioScreen(PretiumController controller){
		this.controller = controller;
		
		InicioLabelField inicio = new InicioLabelField(controller, "Iniciando aplicación...");
		
		add(inicio);	
		
		InicioThread t = new InicioThread(controller, this);
		
		t.start();
		
		
		

	}
	
	
	
	public  void inicializarAplicación(){
		
			try{			
				UiApplication.getUiApplication().pushScreen(new SeleccionClienteScreen(controller));
				
			}catch(Exception e){
				Dialog.inform(e.getMessage());
			}
			
		
	}
	

	
	public void informarExcepción(String mensaje){
		Dialog.inform(mensaje);
	}
	
	

}
This doesnt work too. What I want is the InicioScreen be painted at the begining, while the InicioThread calls the webservice, so the user can see "Application loading...".

Thanks.
Offline  
Old 11-24-2008, 11:15 AM   #10
Ivanov
Talking BlackBerry Encyclopedia
 
Join Date: Apr 2008
Location: Germany, BW
Model: -
PIN: N/A
Carrier: -
Posts: 310
Default

in your extended UiApplication constructor:

- create a screen
- create a ws thread passing a reference of your screen to it.
- push your screen
- start your thread

your thread should call a function when it gets the result, this function updates the screen fields. Take care about event lock
__________________
Blessed is the end user who expects nothing, for he/she will not be disappointed. (Franklin's Rule)
Offline  
Old 11-24-2008, 11:28 AM   #11
sickned
Knows Where the Search Button Is
 
Join Date: Oct 2008
Model: 7100T
PIN: N/A
Carrier: Unknow
Posts: 42
Default

Quote:
Originally Posted by Ivanov View Post
in your extended UiApplication constructor:

- create a screen
- create a ws thread passing a reference of your screen to it.
- push your screen
- start your thread

your thread should call a function when it gets the result, this function updates the screen fields. Take care about event lock
Thanks you very much but this doesnt work.


Code:
public class PretiumMain extends UiApplication{
	

	
	public static void main(String[] args) {
		PretiumMain theApp = new PretiumMain();			
		theApp.enterEventDispatcher();	
		
	}

	public PretiumMain() {

			PretiumController controller = new PretiumController();

			InicioScreen inicio = new InicioScreen(controller);
			
			InicioThread t = new InicioThread(controller, inicio);

			UiApplication.getUiApplication().pushScreen(inicio);
			
			t.start();

	
	}

}
Offline  
Old 11-24-2008, 11:49 AM   #12
sickned
Knows Where the Search Button Is
 
Join Date: Oct 2008
Model: 7100T
PIN: N/A
Carrier: Unknow
Posts: 42
Default

Any help, please?
Offline  
Old 11-25-2008, 04:06 AM   #13
Ivanov
Talking BlackBerry Encyclopedia
 
Join Date: Apr 2008
Location: Germany, BW
Model: -
PIN: N/A
Carrier: -
Posts: 310
Default

what exactly does not work?
If you haven't changed your screen's constructor you have 2 WS calling threads now.
__________________
Blessed is the end user who expects nothing, for he/she will not be disappointed. (Franklin's Rule)
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


Carrier 8.5 Technician Tool Field Assistant USB-L i-Vu USB Link Rnet cable TKIT picture

Carrier 8.5 Technician Tool Field Assistant USB-L i-Vu USB Link Rnet cable TKIT

$198.00



Windows Server 2022 RDS CAL 50 User Key License | | Multilingual picture

Windows Server 2022 RDS CAL 50 User Key License | | Multilingual

$98.00



Used & Tested FSP FSP300-701UJ Server Power Supply picture

Used & Tested FSP FSP300-701UJ Server Power Supply

$153.56



New In Box MOXA NPort 5232 V2.1.0 2-Ports Serial Device Networking Server picture

New In Box MOXA NPort 5232 V2.1.0 2-Ports Serial Device Networking Server

$377.07



XBlue Networks X16 Business Phone System Communications Server And 6 Phones picture

XBlue Networks X16 Business Phone System Communications Server And 6 Phones

$275.00



NEW Moxa NPORT 5650-8-DT RS232 422 485 Device Server picture

NEW Moxa NPORT 5650-8-DT RS232 422 485 Device Server

$864.23







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