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: 468
Registered: ‎08-07-2009
My Device: Curve, Bold, Storm
My Carrier: Blackberry Developer

system listener

i am not able to apply system listener properties.....

 

here is the following code i am applying

 

class displayScreen extends FullScreen implements SystemListener 

{

  private SystemListener systemListener; 

 

 

public void batteryLow() { System.out.println("here I m-------------------------Part"); }

 

public void batteryGood() { System.out.println("here I m-------------------------Part 2"); }

 

public void batteryStatusChange(int status) { System.out.println("here I m-------------------------Part 3"); }

 

public void powerUp() { System.out.println("here I m-------------------------Part 4"); }

 

public void powerOff() { System.out.println("here I m-------------------------Part 5"); } 

 

Application.getApplication().addSystemListener(b);

 

 

 

i hav also set properties System Module, auto run on startup

 

Plz help with suggestion or plz provide me with some code 

 

 

 

----------------------------------------------------------
feel free to press the kudos button on the left side to thank the user that helped you.
please mark posts as solved if you found a solution.
Developer
Posts: 905
Registered: ‎02-07-2009
My Device: BlackBerry Torch 9800
My Carrier: Globe Telecom

Re: system listener

you need to register your SystemListener. 

 

Application.addSystemListener(your listener); 

Developer
Posts: 468
Registered: ‎08-07-2009
My Device: Curve, Bold, Storm
My Carrier: Blackberry Developer

Re: system listener

[ Edited ]

import javax.microedition.io.Connector;

import net.rim.device.api.ui.UiApplication;

import net.rim.device.api.ui.Ui;

import javax.wireless.messaging.MessageListener;

import javax.wireless.messaging.MessageConnection;

import javax.wireless.messaging.TextMessage;

import javax.wireless.messaging.Message;

import net.rim.device.api.system.Alert;

import net.rim.device.api.ui.component.Dialog;

import javax.microedition.io.Datagram;

import javax.microedition.io.DatagramConnection;

import net.rim.device.api.system.Bitmap;

import net.rim.device.api.system.ApplicationManager;

import net.rim.blackberry.api.homescreen.HomeScreen;

import net.rim.device.api.system.DeviceInfo;

import net.rim.device.api.system.Application;

import net.rim.device.api.system.SystemListener;

class MyProject extends UiApplication implements SystemListener{

public static void main(String args[]) {

if (args != null && args.length > 0 && args[0].equals("gui"))

{

//HomeScreen.setRolloverIcon(icon);

final Bitmap regIcon = Bitmap.getBitmapResource("GreyBall.png");

Bitmap icon = Bitmap.getBitmapResource("greenButton.png");

if(myConditionIsTrue) {

HomeScreen.updateIcon(regIcon);

}

else

{

HomeScreen.updateIcon(icon);

}

}

boolean isInStartup = ApplicationManager.getApplicationManager().inStartup();

if (isInStartup) {

System.exit(0);

}

else{

MyProject object = new MyProject();

object.enterEventDispatcher();

Application.getApplication().addSystemListener(object);

}

}

MyProject(){

displayScreen ds= new displayScreen();

Ui.getUiEngine().pushScreen(ds);

}

public void batteryLow(){ System.out.println("her I m-------------------------Part"); } public void batteryGood() { System.out.println("her I m-------------------------Part 2"); } public void batteryStatusChange(int status) { System.out.println("her I m-------------------------Part 3"); }

public void powerUp() { System.out.println("her I m-------------------------Part 4"); } public void powerOff() { System.out.println("her I m-------------------------Part 5"); }

}

 Hi Thanks for the reply...

But the problem here is that When I run it then PowerUp() method is never called.

And when I select the System Module and Auto Run On StartUP properties of project.Then it throws IllegalArgumentException.

Please tell me what basics am I missing... 

Message Edited by Ekansh on 09-02-2009 12:30 PM
----------------------------------------------------------
feel free to press the kudos button on the left side to thank the user that helped you.
please mark posts as solved if you found a solution.
Developer
Posts: 905
Registered: ‎02-07-2009
My Device: BlackBerry Torch 9800
My Carrier: Globe Telecom

Re: system listener

it's because your application is a UiApplication. if you want to have an application that will run on startup, extend the Application and not UiApplication. and if you want your application to have a Ui, then create an alternate entry point where on your startup, that;s the part you add your SystemListener then the icon on your homescreen is where you're entry point to the Ui part.
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: system listener

What you are asking is complicated and difficult to get your head around.  Let us start with the simple things.

 

Your main routine is executed by a Thread in the Operating system, i.e. is not your processing.  It is executed

a) At startup

b) When your icon is clicked (assuming that the application is not already running).

We shall ignore alternate entry points for the moment, they can confuse things and I generally avoid them, but that is another story...

 

Anyway, the point here is that the code in main() should really just get your application going.  How does it do that?  By executing the magic method "enterEventDispatcher()".  This method never returns, following code in the main method is ignored.

 

So we can immediately see 2 problems with your code:

1) Calling System.exit(..) -  

        if (isInStartup) {           

             System.exit(0);       

        } 

You are calling System.exit() on a System Thread.  No wonder it is illegal.

 

2) Code after "enterEventDispatcher()". 

        object.enterEventDispatcher();           

        Application.getApplication().addSystemListener(object);

 

I'm sorry I don't have time to correct this code.  I suggest that you think about what you are trying to do, and review the auto-start and startup KB articles in the KnowledgeBase.  I think this one is particularly useful:

 

How to - Detect system availability on startup 
Article Number: DB-00642
http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800901/How_to_-_Detec...

I'm sure you will make some progress, using this, then hit another wall.  If so, post some more code. 

Developer
Posts: 468
Registered: ‎08-07-2009
My Device: Curve, Bold, Storm
My Carrier: Blackberry Developer

Re: system listener

Hi,

Thanks Peter and johnbibs .

Actually I want to use check batteryGood() under SystemListener.

PowerUp() method is called during startUp.But the Problem is that my application icon doesnot display.

I want to display dialog based on the batteryGood() method.

For more clearity I want to use SystemListener along with the UI part

i may be missing some basic. 

----------------------------------------------------------
feel free to press the kudos button on the left side to thank the user that helped you.
please mark posts as solved if you found a solution.
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: system listener

I am confused now.  You want to check batteryGood()?  batteryGood() is called by the System, it is not something you check.

 

Let us start wit the basics.  You should create an application that does what you want, via an icon, first.  Then if you need to do something specific at startup time, then you change the startup. So first create your application with an icon with no autostart.  Then we can help you autostart it. 

 

But please clarify what you want this application to do.

Developer
Posts: 905
Registered: ‎02-07-2009
My Device: BlackBerry Torch 9800
My Carrier: Globe Telecom

Re: system listener

i suggest that you implement a background application and just create an alternate entry point for its UI component.

check this http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800901/How_To_-_Setup...

 

 

then implement a systemlistener.  

then to register your listener,

 given the code below

 

class MyProject extends Application {

 public MyProject(){

  this.addSystemListener(new MySystemListener());

 

class MySystemListener implements SystemListener{

  //your implementation here