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
egirotto
Posts: 42
Registered: ‎06-14-2010
My Device: 8900 Bold, 9300
My Carrier: Vodafone
Accepted Solution

Detect lock button pressed

Hi,

 

I need to detect if the user press the lock button on the top left of BB (is a 8900 bold).

I read in a post that there isn't a specific listener but is possible to detect it implementing a MemoryCleanerListener because as RIM say:

 

"By default, the memory cleaner application runs on a BlackBerry® device when the BlackBerry device is inactive for a specified period of time. You or a BlackBerry device user can change when the memory cleaner application runs when any the following conditions exist:

  • The BlackBerry device user synchronizes the BlackBerry device with a computer.
  • The BlackBerry device user locks the BlackBerry device.
  • The BlackBerry device locks after it is inactive for a specified period of time.
  • The BlackBerry device user changes the time or time zone on the BlackBerry device."
I try it with something like this in my main application class:
MemoryCleanerDaemon.addListener(new MemoryCleanerListener() {
		
  public String getDescription() {
	return "listener";
  }
		
  public boolean cleanNow(int event) {
    if (event==MemoryCleanerListener.EVENT_DEVICE_LOCK){
	//do something
    }
    return false;
}
	

 

I try it in simulator with debbugger with a break point in the first line of listener but when i press the button nothing happens.
Any idea?
Thanks for help!
Please use plain text.
Contributor
egirotto
Posts: 42
Registered: ‎06-14-2010
My Device: 8900 Bold, 9300
My Carrier: Vodafone

Re: Detect lock button pressed

Hi,

 

I resolve the problem moving the MemoryCleanerDaemon.addListener after the enterEventDispatcher.

 

The MemoryCleanerListener working and using ApplicationManager method isSystemLocked I know when the user press to lock and when to unlock

 

Best regards

Please use plain text.
Trusted Contributor
Thecr0w
Posts: 178
Registered: ‎02-20-2011
My Device: 8700
My Carrier: at&t

Re: Detect lock button pressed

Does it work well in os 5.0 or 6.0?Or are you do it in os 5.0 or 6.0?

# I tried to change the world, but I couldn't find the source code #



Please use plain text.
New Contributor
lokiBB
Posts: 7
Registered: ‎05-04-2011
My Device: Curve 3G 9330
My Carrier: Airtel

Re: Detect lock button pressed

[ Edited ]

egirotto wrote:

Hi,

 

I resolve the problem moving the MemoryCleanerDaemon.addListener after the enterEventDispatcher.

 

The MemoryCleanerListener working and using ApplicationManager method isSystemLocked I know when the user press to lock and when to unlock

 

Best regards



if you move emoryCleanerDaemon.addListener after the enterEventDispatcher. MemoryCleanerDaemon.addListener wont get executed right?

i dont know how you got it working. enterEventDispatcher will make main thread to listen for the UI events right?

After entering to event listening it wont come back to execute MemoryCleanerDaemon.addListener right?

any one please help me. i want to know when user presses lock button. I used following code but not getting the event. Even if i place MemoryCleanerDaemon.addListener before theApp.enterEventDispatcher() also i am not getting the event. please help.

public static void main( String[] args ) {
        // Create a new instance of the application and make the currently
        // running thread the application's event dispatch thread.
        HelloBlackBerry theApp = new HelloBlackBerry();
		theApp.enterEventDispatcher();
        MemoryCleanerDaemon.addListener(new MemoryCleanerListener() {
			   public boolean cleanNow(int event) {
			       if(event==MemoryCleanerListener.EVENT_DEVICE_LOCK){
			           //do something
			    	   System.out.println("EVENT_DEVICE_LOCK");
			        }
				   System.out.println("--------------------EVENT_DEVICE_LOCK---------------------------------------");
			       return false;
			   }
			   public String getDescription() {
			       // TODO Auto-generated method stub
			      return "listener";
			    } 
			 });
    }

 

 

Please use plain text.
New Contributor
MalaWidiyanto
Posts: 6
Registered: ‎02-28-2013
My Device: BB OS 7
My Carrier: BB 9900

Re: Detect lock button pressed

I have the same problem, anyone can help us to solve it? please :Angel:

Please use plain text.
New Contributor
MalaWidiyanto
Posts: 6
Registered: ‎02-28-2013
My Device: BB OS 7
My Carrier: BB 9900

Re: Detect lock button pressed

I have solve my similar problem with this methode :
- Backlight.isEnable()
- Backlight.enable(false);

- Backlight.enable(true);

check this out : http://www.blackberry.com/developers/docs/5.0.0api/net/rim/device/api/system/Backlight.html

Please use plain text.