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: 587
Registered: ‎04-01-2009
My Device: Z10, PlayBook
My Carrier: NA

How to wait for an event

I'd like my application to know when the user starts charging their device (ex. in the charging pod).

 

One possible approach is to run a thread that, once each second, checks the value of the getBatteryStatus().

 

Is there a cleaner way to do such a thing, whereby an event in my application would be fired when this value changes?

 

Developer
Posts: 1,477
Registered: ‎12-30-2008
My Device: Torch 9810

Re: How to wait for an event

You can use SystemListener for this purpose... Have a look at this thread just for reference

http://supportforums.blackberry.com/rim/board/message?board.id=java_dev&thread.id=29094

 

Use the following method from system listener..

 

public void batteryStatusChange(int status)

 

If(status == DeviceInfo.BSTAT_CHARGING)

{

//your code

}

 

This is the cleaner way of achieving this..

 

Thanks! 

 

--
Manimaran Selvan
Co-Founder, Tech Lead,
Equity Markets Research Group
Highlighted
Developer
Posts: 1,477
Registered: ‎12-30-2008
My Device: Torch 9810

Re: How to wait for an event

This KB article will give you a good learning about SystemListener

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800620/How_to_...

 

Cheers.. 

--
Manimaran Selvan
Co-Founder, Tech Lead,
Equity Markets Research Group