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
Contributor
Posts: 40
Registered: ‎01-14-2011
My Device: Not Specified

What runs while power off?

Hi,

 

I've noticed that some system threads continue to run when the device is powered down and others (including my app threads) seem to be suspended.

 

So my question is, what exactly does power down do to the execution of my app and its threads?

 

Regards,

Dave

Contributor
Posts: 40
Registered: ‎01-14-2011
My Device: Not Specified

Re: What runs while power off?

In fact, it seems that only *some* of my threads get suspended...

Developer
Posts: 374
Registered: ‎02-12-2011
My Device: Bold 9780
My Carrier: Wind Mobile

Re: What runs while power off?

[ Edited ]

I seem to notice this somewhat to, for example I have some LED changes during different events in the thread to keep me informed of what is happening.

Evidently while the phone is off the LED turns to the colour in the thread that I have set it to blink (although it stays solid) and is supposed to turn off after GPS coordinates have been acquired, the LED stays lit and when I turn my phone on it proceeds to get the GPS lock.

I would rather it suspend or pause the thread until the phone is back on so the outcome isn't so unpredictable.

 

So, for example my thread looks like

 

class myThread extends Thread {

	public void run() {
		boolean bRun = true;
		try {
			Thread.sleep(60000);
		} catch (InterruptedException e1) {
		}           
    
		while (bRun == true)
		{
			LED.setState(LED.STATE_BLINKING);
			gpsCheck();
			LED.setState(LED.STATE_OFF);
		
			try {
				sleep(60000 * 30);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
}

 
If I have my phone on sleep overnight, when I wake up and turn it on the thread isnt ever run anymore (I know because I have a vibrate alert inside the gps check function).

 

I need to restart the app to get it going again. 

Developer
Posts: 141
Registered: ‎02-10-2010
My Device: 9500
My Carrier: Airtel

Re: What runs while power off?


I recommend you to:
1. Handle exceptions where necessary for all the important API calls.
2. Debug using BlackBerry Event Logger in this case. Use EventLogger.logEvent.

You can check event logs using the key sequence lglg while keeping the ALT key down.
Developer
Posts: 374
Registered: ‎02-12-2011
My Device: Bold 9780
My Carrier: Wind Mobile

Re: What runs while power off?

Well that doesn't stop it from running when the phone is off does it? I dont want it to run when the phone is off, but continue running when the phone is turned on

Developer
Posts: 141
Registered: ‎02-10-2010
My Device: 9500
My Carrier: Airtel

Re: What runs while power off?

This was to help you debug the issue. Your application is probably crashing due to some exception during the long sleep. Please try the following:
1. Handle Throwable instead of InterruptedException
2. Try a shorter sleep interval of about 3 minutes or less. It is too huge right now.

The ideal solution would be to use timer instead of the long sleep intervals:
http://www.blackberry.com/developers/docs/6.0.0api/java/util/Timer.html
Developer
Posts: 374
Registered: ‎02-12-2011
My Device: Bold 9780
My Carrier: Wind Mobile

Re: What runs while power off?

I see, thanks for the suggestion.

 

If my app was crashing wouldn't the UI crash too? Because when I hold the Menu button on the blackberry and see the running apps mine is still shown, and I can click it and enter the UI.


Shorter sleep would hurt the battery too much because of the GPS call.

 

I tried a timer, but I think there is an issue when turning off the phone and the time that was set for the timer was passed, therefore it is not re-timed and stopped for good.

 

You might be right about the exceptions, although I think I did catch all of them inside the GPS call, I suppose I will try removing the call and just have vibrate + LED alerts so I can check.

 

Thanks

Developer
Posts: 374
Registered: ‎02-12-2011
My Device: Bold 9780
My Carrier: Wind Mobile

Re: What runs while power off?

[ Edited ]

Ok, you are definitely right, it is crashing. I think its crashing when the GPS fails (e.g. Inside a concrete building and cant get GPS lock) but I dont know why that would cause it to do that. You have my thread code above and this is the code for GPS.

 

	static private Coordinates gpsCheck() {
		Coordinates myCoordinates = null;
		
		LocationProvider locationProvider = null;
		try {
			locationProvider = LocationProvider.getInstance(null);
		} catch (LocationException e) {
			}

		if (locationProvider == null) {

		} else {
			switch (locationProvider.getState()) {
			case LocationProvider.AVAILABLE:
				Location location = null;
				int timeout = 120;
				try {
					location = locationProvider.getLocation(timeout);
				} catch (LocationException e) {
				} catch (InterruptedException e) {
				} catch (Exception e) {
				}

				if (location != null && location.isValid()) {
					myCoordinates = location.getQualifiedCoordinates();
					return myCoordinates;
				}
				break;
			}
		}
		return null;
	}

 

I am catching everything, I dont need any code to be executed when it fails, returning false will suffice. So I dont understand why the thread would crash whenever I dont get GPS signal when it checks.

Developer
Posts: 141
Registered: ‎02-10-2010
My Device: 9500
My Carrier: Airtel

Re: What runs while power off?

I recommend you to do the following change: catch Throwable in both the catch blocks in gpsCheck() function.

 

Highlighted
Developer
Posts: 141
Registered: ‎02-10-2010
My Device: 9500
My Carrier: Airtel

Re: What runs while power off?

[ Edited ]

One quick question:Why are you using your own timer/ other ways to receive the location updates?

 

For location tracking, the straight forward way is to implement LocationListener and add to the location provider using setLocationListener API. In this case, you need to get the LocationProvider instance just once and you keep getting the location & provider state updates in the class implementing LocationListener.

 

I recommend you to also explore the following knowledge base articles:

1. Simple Location API (if that can suffice your purpose):

http://supportforums.blackberry.com/t5/Java-Development/Simple-Location-API/ta-p/1145951

2. Location APIs usage article:

http://supportforums.blackberry.com/t5/Java-Development/Location-APIs-Start-to-finish/ta-p/571949